Skip to main content

FakeProvider

Struct FakeProvider 

Source
pub struct FakeProvider { /* private fields */ }
Expand description

A programmable fake Provider — a script is a sequence of per-turn replies, consumed in order by chat / stream_chat.

  • Each call consumes one script turn and records the request; once the script is exhausted, calls return ProviderError::Api(“script exhausted”) and do not replay — an Agent running an extra turn fails explicitly right away in tests;
  • chat and stream_chat consume the same script with the same semantics, differing only in how the reply is delivered (an event stream = several increments + one Done);
  • requests returns a snapshot of the received request history for tests to assert what the Agent sent to the model — since a fake is lenient (e.g. if the Agent forgets to feed back tool results, a real API would error but the fake would not), this is the only way to catch such process bugs.

§Examples

use molo::message::Message;
use molo::provider::{ChatRequest, FakeProvider, FakeReply, Provider};

let fake = FakeProvider::new([
    FakeReply::Text("hi".into()),
    FakeReply::Text("bye".into()),
]);

let r = fake.chat(ChatRequest::default()).await?;
assert_eq!(r.message, Message::assistant("hi"));

Implementations§

Source§

impl FakeProvider

Source

pub fn new(replies: impl IntoIterator<Item = FakeReply>) -> Self

Constructs from a script sequence; chat / stream_chat consume it in order and error once exhausted.

Source

pub fn push(&self, reply: FakeReply)

Appends one reply to the end of the script (for staged injection in tests).

Source

pub fn requests(&self) -> Vec<ChatRequest>

A snapshot of the received request history, for tests to assert what the Agent sent to the model.

§Examples
use molo::message::Message;
use molo::provider::{ChatRequest, FakeProvider, FakeReply, Provider};

let fake = FakeProvider::new([FakeReply::Text("hi".into())]);
fake.chat(ChatRequest {
    messages: vec![Message::user("hi")],
    ..Default::default()
})
.await?;

assert_eq!(fake.requests()[0].messages, vec![Message::user("hi")]);

Trait Implementations§

Source§

impl Clone for FakeProvider

Source§

fn clone(&self) -> Self

Clones are independent copies: each holds and consumes its own script queue and request history without affecting the other (script calls made before the clone still consume from the start in the clone).

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FakeProvider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FakeProvider

Source§

fn default() -> FakeProvider

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

impl Provider for FakeProvider

Source§

fn chat<'life0, 'async_trait>( &'life0 self, request: ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends one turn of conversation and returns the model’s reply (text, or a request to call tools). Read more
Source§

fn stream_chat<'life0, 'async_trait>( &'life0 self, request: ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<BoxStream<'static, Result<StreamEvent, ProviderError>>, ProviderError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Streams one turn of conversation, returning the Assistant’s reply incrementally. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more