pub struct MockTurn { /* private fields */ }Expand description
One scripted model response for MockModel.
A content turn streams its blocks as an assistant message; its stop reason is ToolUse when it
holds a tool use and EndTurn otherwise, unless set. An event turn streams the given events
as they are. Either can end with an error, and an error turn streams nothing but its error.
Implementations§
Source§impl MockTurn
impl MockTurn
Sourcepub fn content(
blocks: impl IntoIterator<Item = impl Into<ContentBlock>>,
) -> Self
pub fn content( blocks: impl IntoIterator<Item = impl Into<ContentBlock>>, ) -> Self
A turn that streams blocks as an assistant message.
Sourcepub fn events(
events: impl IntoIterator<Item = impl Into<ModelStreamEvent>>,
) -> Self
pub fn events( events: impl IntoIterator<Item = impl Into<ModelStreamEvent>>, ) -> Self
A turn that streams events unchanged.
Sourcepub fn error(error: impl Fn() -> Error + Send + Sync + 'static) -> Self
pub fn error(error: impl Fn() -> Error + Send + Sync + 'static) -> Self
A turn that fails with the error error builds, each time the turn is used.
Sourcepub fn throttled(message: impl Into<String>) -> Self
pub fn throttled(message: impl Into<String>) -> Self
A turn that fails with a ModelThrottledError.
Sourcepub fn with_error(
self,
error: impl Fn() -> Error + Send + Sync + 'static,
) -> Self
pub fn with_error( self, error: impl Fn() -> Error + Send + Sync + 'static, ) -> Self
Ends the turn with the error error builds, after its events.
Sourcepub fn with_stop_reason(self, stop_reason: StopReason) -> Self
pub fn with_stop_reason(self, stop_reason: StopReason) -> Self
Sets the stop reason of a content turn.
Sourcepub fn with_usage(self, usage: Usage) -> Self
pub fn with_usage(self, usage: Usage) -> Self
Adds a metadata event with usage after the message of a content turn.
Sourcepub fn with_delay(self, delay: Duration) -> Self
pub fn with_delay(self, delay: Duration) -> Self
Waits for delay on the tokio timer before streaming. Use tokio::time::pause in tests so
no real time passes.
Trait Implementations§
Source§impl From<ContentBlock> for MockTurn
impl From<ContentBlock> for MockTurn
Source§fn from(block: ContentBlock) -> Self
fn from(block: ContentBlock) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for MockTurn
impl !UnwindSafe for MockTurn
impl Freeze for MockTurn
impl Send for MockTurn
impl Sync for MockTurn
impl Unpin for MockTurn
impl UnsafeUnpin for MockTurn
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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> ⓘ
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> ⓘ
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 more