pub struct ScriptedResponse { /* private fields */ }Expand description
What a ScriptedLlm answers to one generate_content call.
A reply is a stream of responses, optionally followed by a stream error, or a call that
fails outright. Build one with text, function_call,
stream or error; an LlmResponse converts into a
one-response reply.
§Example
use adk_core::{AdkError, UsageMetadata};
use adk_model::ScriptedResponse;
use serde_json::json;
let call = ScriptedResponse::function_call("get_weather", json!({ "city": "Nairobi" }));
let answer = ScriptedResponse::text("It is sunny.")
.with_usage(UsageMetadata { prompt_token_count: 12, ..Default::default() });
let cut = ScriptedResponse::text("It is").then_error(AdkError::model("stream reset"));
let refused = ScriptedResponse::error(AdkError::model("rate limited"));Implementations§
Source§impl ScriptedResponse
impl ScriptedResponse
Sourcepub fn function_call(name: impl Into<String>, args: Value) -> Self
pub fn function_call(name: impl Into<String>, args: Value) -> Self
A final model response with one function call.
The call has no ID; ScriptedLlm assigns one when it replies.
Sourcepub fn function_calls<N: Into<String>>(
calls: impl IntoIterator<Item = (N, Value)>,
) -> Self
pub fn function_calls<N: Into<String>>( calls: impl IntoIterator<Item = (N, Value)>, ) -> Self
A final model response with several function calls, in order.
Sourcepub fn response(response: LlmResponse) -> Self
pub fn response(response: LlmResponse) -> Self
A reply of exactly response.
Sourcepub fn stream(responses: impl IntoIterator<Item = LlmResponse>) -> Self
pub fn stream(responses: impl IntoIterator<Item = LlmResponse>) -> Self
A reply that streams responses in order, as given.
Sourcepub fn error(error: AdkError) -> Self
pub fn error(error: AdkError) -> Self
A call that fails: generate_content returns error instead of a stream.
Sourcepub fn then_error(self, error: AdkError) -> Self
pub fn then_error(self, error: AdkError) -> Self
Ends the stream with error after its responses, as a provider whose stream breaks.
Sourcepub fn with_usage(self, usage: UsageMetadata) -> Self
pub fn with_usage(self, usage: UsageMetadata) -> Self
Reports usage on the reply’s last response.
Trait Implementations§
Source§impl Debug for ScriptedResponse
impl Debug for ScriptedResponse
Source§impl From<AdkError> for ScriptedResponse
impl From<AdkError> for ScriptedResponse
Source§impl From<LlmResponse> for ScriptedResponse
impl From<LlmResponse> for ScriptedResponse
Source§fn from(response: LlmResponse) -> Self
fn from(response: LlmResponse) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl !RefUnwindSafe for ScriptedResponse
impl !UnwindSafe for ScriptedResponse
impl Forget for ScriptedResponse
impl Freeze for ScriptedResponsewhere
*const u8 is !null: Freeze,
PhantomData<LlmResponse>: Freeze,
&'static str: Freeze,
PhantomData<u8>: Freeze,
*const ErrorDetails is !null: Freeze,
PhantomData<ErrorDetails>: Freeze,
*const dyn Error + Sync + Send is !null: Freeze,
PhantomData<dyn Error + Sync + Send>: Freeze,
impl Move for ScriptedResponse
impl Send for ScriptedResponse
impl Sync for ScriptedResponse
impl Unpin for ScriptedResponse
impl UnsafeUnpin for ScriptedResponsewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<LlmResponse>: UnsafeUnpin,
&'static str: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ErrorDetails is !null: UnsafeUnpin,
PhantomData<ErrorDetails>: UnsafeUnpin,
*const dyn Error + Sync + Send is !null: UnsafeUnpin,
PhantomData<dyn Error + Sync + Send>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::RequestCreates a shared type from an unshared type.