pub struct MockCompletionModel { /* private fields */ }Available on crate feature
test-utils only.Expand description
A cloneable scripted CompletionModel for tests.
Each completion or stream call consumes exactly one scripted turn. If no turn
is available, the model returns CompletionError::ProviderError with a
clear message instead of repeating previous responses.
Implementations§
Source§impl MockCompletionModel
impl MockCompletionModel
Sourcepub fn new(turns: impl IntoIterator<Item = MockTurn>) -> Self
pub fn new(turns: impl IntoIterator<Item = MockTurn>) -> Self
Create a mock model from scripted non-streaming turns.
Sourcepub fn text(text: impl Into<String>) -> Self
pub fn text(text: impl Into<String>) -> Self
Create a mock model that returns one text completion.
Sourcepub fn from_turns(turns: impl IntoIterator<Item = MockTurn>) -> Self
pub fn from_turns(turns: impl IntoIterator<Item = MockTurn>) -> Self
Create a mock model from scripted non-streaming turns.
Sourcepub fn from_stream_turns(
stream_turns: impl IntoIterator<Item = impl IntoIterator<Item = MockStreamEvent>>,
) -> Self
pub fn from_stream_turns( stream_turns: impl IntoIterator<Item = impl IntoIterator<Item = MockStreamEvent>>, ) -> Self
Create a mock model from scripted streaming turns.
Sourcepub fn requests(&self) -> Vec<CompletionRequest>
pub fn requests(&self) -> Vec<CompletionRequest>
Return cloned requests received by this model.
Sourcepub fn request_count(&self) -> usize
pub fn request_count(&self) -> usize
Return the number of requests received by this model.
Trait Implementations§
Source§impl Clone for MockCompletionModel
impl Clone for MockCompletionModel
Source§fn clone(&self) -> MockCompletionModel
fn clone(&self) -> MockCompletionModel
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl CompletionModel for MockCompletionModel
impl CompletionModel for MockCompletionModel
Source§type Response = MockResponse
type Response = MockResponse
The raw response type returned by the underlying completion model.
Source§type StreamingResponse = MockResponse
type StreamingResponse = MockResponse
The raw response type returned by the underlying completion model when streaming.
Source§fn make(_: &Self::Client, _: impl Into<String>) -> Self
fn make(_: &Self::Client, _: impl Into<String>) -> Self
Construct a model handle from a provider client and model identifier.
Source§async fn completion(
&self,
request: CompletionRequest,
) -> Result<CompletionResponse<Self::Response>, CompletionError>
async fn completion( &self, request: CompletionRequest, ) -> Result<CompletionResponse<Self::Response>, CompletionError>
Generates a completion response for the given completion request.
async fn stream( &self, request: CompletionRequest, ) -> Result<StreamingCompletionResponse<Self::StreamingResponse>, CompletionError>
Source§fn completion_request(
&self,
prompt: impl Into<Message>,
) -> CompletionRequestBuilder<Self>
fn completion_request( &self, prompt: impl Into<Message>, ) -> CompletionRequestBuilder<Self>
Generates a completion request builder for the given
prompt.Source§impl Default for MockCompletionModel
impl Default for MockCompletionModel
Source§fn default() -> MockCompletionModel
fn default() -> MockCompletionModel
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for MockCompletionModel
impl RefUnwindSafe for MockCompletionModel
impl Send for MockCompletionModel
impl Sync for MockCompletionModel
impl Unpin for MockCompletionModel
impl UnsafeUnpin for MockCompletionModel
impl UnwindSafe for MockCompletionModel
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
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> 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 more