pub struct FakeChatModel { /* private fields */ }Expand description
A fake chat model for testing without API calls.
Returns pre-configured responses in order. Tracks call count and can inject errors at specified positions.
§Examples
use synwire_core::language_models::fake::FakeChatModel;
use synwire_core::language_models::traits::BaseChatModel;
use synwire_core::messages::Message;
let model = FakeChatModel::new(vec!["Hello!".into()]);
let messages = vec![Message::human("Hi")];
let result = model.invoke(&messages, None).await.unwrap();
assert_eq!(result.message.content().as_text(), "Hello!");Implementations§
Source§impl FakeChatModel
impl FakeChatModel
Sourcepub const fn new(responses: Vec<String>) -> Self
pub const fn new(responses: Vec<String>) -> Self
Creates a new fake chat model with the given responses.
Responses are returned in order, cycling back to the start when all responses have been used.
Sourcepub const fn with_error_at(self, index: usize) -> Self
pub const fn with_error_at(self, index: usize) -> Self
Sets the call index at which to return an error.
When the zero-based call count matches index, the model
returns a ModelError::Other instead of a response.
Sourcepub const fn with_chunk_size(self, size: usize) -> Self
pub const fn with_chunk_size(self, size: usize) -> Self
Sets the chunk size for streaming responses.
When set, the stream method splits each
response into chunks of at most size characters.
Sourcepub const fn with_stream_error_after(self, n: usize) -> Self
pub const fn with_stream_error_after(self, n: usize) -> Self
Configures an error to be injected after n chunks during streaming.
The stream yields the first n chunks successfully, then returns
an error for every subsequent chunk position.
Sourcepub fn call_count(&self) -> usize
pub fn call_count(&self) -> usize
Returns the number of times invoke has been called.