pub struct MockProvider { /* private fields */ }Expand description
Deterministic LLM provider for tests.
Queue responses with the builder API, then call complete() to
consume them in FIFO order.
§Example
use pe_core::mock_provider::MockProvider;
use pe_core::llm::LlmProvider;
let provider = MockProvider::new()
.respond_with("Hello!")
.respond_with("Goodbye!");
let r1 = provider.complete(&[], &[]).await.unwrap();
assert_eq!(r1.message.content.as_text(), Some("Hello!"));
let r2 = provider.complete(&[], &[]).await.unwrap();
assert_eq!(r2.message.content.as_text(), Some("Goodbye!"));Implementations§
Source§impl MockProvider
impl MockProvider
Sourcepub fn respond_with(self, text: impl Into<String>) -> Self
pub fn respond_with(self, text: impl Into<String>) -> Self
Queue a plain text response.
Sourcepub fn respond_with_tool_call(
self,
tool_name: impl Into<String>,
args: Value,
) -> Self
pub fn respond_with_tool_call( self, tool_name: impl Into<String>, args: Value, ) -> Self
Queue a tool call response.
Sourcepub fn respond_with_error(self, err: PeError) -> Self
pub fn respond_with_error(self, err: PeError) -> Self
Queue an error response.
Sourcepub fn with_embedding(self, embedding: Vec<f32>) -> Self
pub fn with_embedding(self, embedding: Vec<f32>) -> Self
Set the embedding to return for all embed() calls.
Trait Implementations§
Source§impl Default for MockProvider
impl Default for MockProvider
Source§impl LlmProvider for MockProvider
impl LlmProvider for MockProvider
Source§fn complete(
&self,
_messages: &[Message],
_tools: &[ToolSchema],
) -> Pin<Box<dyn Future<Output = Result<LlmResponse, PeError>> + Send + '_>>
fn complete( &self, _messages: &[Message], _tools: &[ToolSchema], ) -> Pin<Box<dyn Future<Output = Result<LlmResponse, PeError>> + Send + '_>>
Non-streaming completion. Returns the full response. Read more
Source§fn stream(
&self,
_messages: &[Message],
_tools: &[ToolSchema],
) -> StreamFuture<'_>
fn stream( &self, _messages: &[Message], _tools: &[ToolSchema], ) -> StreamFuture<'_>
Streaming completion. Yields tokens (and tool call deltas) as they arrive. Read more
Source§fn embed(
&self,
_text: &str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, PeError>> + Send + '_>>
fn embed( &self, _text: &str, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, PeError>> + Send + '_>>
Embed text into a vector. Used for semantic routing and memory search.
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Human-readable provider name for logging (“openai”, “anthropic”, “mock”).
Auto Trait Implementations§
impl !Freeze for MockProvider
impl RefUnwindSafe for MockProvider
impl Send for MockProvider
impl Sync for MockProvider
impl Unpin for MockProvider
impl UnsafeUnpin for MockProvider
impl UnwindSafe for MockProvider
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