Skip to main content

MockProvider

Struct MockProvider 

Source
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

Source

pub fn new() -> Self

Create a new MockProvider with an empty response queue.

Source

pub fn respond_with(self, text: impl Into<String>) -> Self

Queue a plain text response.

Source

pub fn respond_with_tool_call( self, tool_name: impl Into<String>, args: Value, ) -> Self

Queue a tool call response.

Source

pub fn respond_with_error(self, err: PeError) -> Self

Queue an error response.

Source

pub fn with_embedding(self, embedding: Vec<f32>) -> Self

Set the embedding to return for all embed() calls.

Source

pub fn remaining(&self) -> usize

Number of responses remaining in the queue.

Trait Implementations§

Source§

impl Default for MockProvider

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl LlmProvider for MockProvider

Source§

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<'_>

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 + '_>>

Embed text into a vector. Used for semantic routing and memory search.
Source§

fn provider_name(&self) -> &'static str

Human-readable provider name for logging (“openai”, “anthropic”, “mock”).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.