pub struct MockLLMClient { /* private fields */ }Expand description
Mock LLM client for testing - doesn’t make real API calls.
This is useful for writing fast unit tests without requiring actual LLM API access.
§Examples
use runtime::llm::{MockLLMClient, LLMClient, LLMResponse};
use runtime::llm::types::Message;
let client = MockLLMClient::new("Hello from mock!");
let messages = vec![Message {
role: "user".to_string(),
content: "Say hello".to_string(),
}];
let result: LLMResponse<String> = client
.complete::<LLMResponse<String>, String>(&messages, &[])
.await
.expect("Mock LLM failed");Implementations§
Source§impl MockLLMClient
impl MockLLMClient
Sourcepub fn new(response: &str) -> Self
pub fn new(response: &str) -> Self
Creates a new mock LLM client that returns the specified response.
§Arguments
response- A string that will be parsed as the response content
§Examples
use runtime::llm::MockLLMClient;
// For structured responses, provide JSON
let client = MockLLMClient::new(r#"{"field": "value"}"#);
// For simple text responses
let client = MockLLMClient::new("Hello, world!");Sourcepub fn default_hello() -> Self
pub fn default_hello() -> Self
Creates a mock LLM client with a default “Hello” response.
§Examples
use runtime::llm::MockLLMClient;
let client = MockLLMClient::default_hello();Trait Implementations§
Source§impl LLMClient for MockLLMClient
impl LLMClient for MockLLMClient
Source§fn complete<'life0, 'life1, 'life2, 'async_trait, T, C>(
&'life0 self,
_messages: &'life1 [Message],
_tools: &'life2 [ToolSpec],
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>where
T: LLMResponseTrait<C> + Default + Send + 'async_trait,
C: for<'de> Deserialize<'de> + Default + Send + Serialize + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn complete<'life0, 'life1, 'life2, 'async_trait, T, C>(
&'life0 self,
_messages: &'life1 [Message],
_tools: &'life2 [ToolSpec],
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>where
T: LLMResponseTrait<C> + Default + Send + 'async_trait,
C: for<'de> Deserialize<'de> + Default + Send + Serialize + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Send messages to LLM and get a response
Auto Trait Implementations§
impl Freeze for MockLLMClient
impl RefUnwindSafe for MockLLMClient
impl Send for MockLLMClient
impl Sync for MockLLMClient
impl Unpin for MockLLMClient
impl UnwindSafe for MockLLMClient
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§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> 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