pub struct FakeTextModel { /* private fields */ }Expand description
An in-memory TextModel for module tests: records every Prompt
it completed and answers according to its TextModelMode.
The mode is global by default and can be overridden per tier
(FakeTextModel::set_mode_for), mirroring FakePush’s
per-recipient override — the natural analogue, and the thing the port
exists for: one test can wire the fast tier to a drafted reply and the
strong tier to a refusal, and watch a module treat the two differently
without either vendor being named.
A completion that answered NotConfigured or failed is not
recorded, the same rule FakePush applies to a send — the recording
means “the model answered”, and a caller that retried on
Transient { .. } then sees one recorded prompt per attempt it got an
answer for.
Implementations§
Source§impl FakeTextModel
impl FakeTextModel
pub fn new(mode: TextModelMode) -> Self
Sourcepub fn prompts(&self) -> Vec<Prompt>
pub fn prompts(&self) -> Vec<Prompt>
Every prompt answered so far, in order. A completion that answered
NotConfigured or failed is not recorded.
Sourcepub fn set_mode(&self, mode: TextModelMode)
pub fn set_mode(&self, mode: TextModelMode)
Switches the mode every tier without an override answers with
(e.g. flip to NotConfigured mid-test).
Sourcepub fn set_mode_for(&self, tier: ModelTier, mode: TextModelMode)
pub fn set_mode_for(&self, tier: ModelTier, mode: TextModelMode)
Makes one tier answer with mode, whatever the global mode is —
the fast tier drafting and the strong tier refusing, say.
Sourcepub fn clear_mode_for(&self, tier: ModelTier)
pub fn clear_mode_for(&self, tier: ModelTier)
Drops one tier’s override, putting it back on the global mode.
Sourcepub fn mode_for(&self, tier: ModelTier) -> TextModelMode
pub fn mode_for(&self, tier: ModelTier) -> TextModelMode
The mode tier will answer with.
Trait Implementations§
Source§impl Clone for FakeTextModel
impl Clone for FakeTextModel
Source§impl Default for FakeTextModel
impl Default for FakeTextModel
Source§impl TextModel for FakeTextModel
impl TextModel for FakeTextModel
Source§fn complete<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 Prompt,
) -> Pin<Box<dyn Future<Output = Result<Completion, TextModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn complete<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: &'life1 Prompt,
) -> Pin<Box<dyn Future<Output = Result<Completion, TextModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
prompt. Read moreSource§fn supports(&self, _tier: ModelTier, capability: Capability) -> bool
fn supports(&self, _tier: ModelTier, capability: Capability) -> bool
capability for a prompt routed to
tier. Defaults to false: a model that has not opted in is
refused a tools-bearing prompt by RoutingTextModel and
run_tool_loop before it is ever called,
rather than sent a request it would silently drop the tools from.
An adapter that carries Capability::Tools or
Capability::Images overrides this to answer true for it. Read moreSource§fn stream<'a>(
&'a self,
prompt: &'a Prompt,
) -> Pin<Box<dyn Stream<Item = Result<TextDelta, TextModelError>> + Send + 'a>>
fn stream<'a>( &'a self, prompt: &'a Prompt, ) -> Pin<Box<dyn Stream<Item = Result<TextDelta, TextModelError>> + Send + 'a>>
prompt as TextDeltas (issue #859). The default
implementation makes one complete round trip — the same provider
exchange, the same cost — and answers its result decomposed by
completion_deltas, so an adapter written before this method
existed streams without a change. An adapter whose provider
streams natively overrides it; a caller cannot tell the difference
except by timing (and by Completion::json, which only a
buffered structured-output call can fill). Read moreAuto Trait Implementations§
impl Freeze for FakeTextModel
impl RefUnwindSafe for FakeTextModel
impl Send for FakeTextModel
impl Sync for FakeTextModel
impl Unpin for FakeTextModel
impl UnsafeUnpin for FakeTextModel
impl UnwindSafe for FakeTextModel
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<M> TextModelExt for M
impl<M> TextModelExt for M
Source§fn complete_json<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: Prompt,
schema: &'life1 Schema,
) -> Pin<Box<dyn Future<Output = Result<Value, TextModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
M: 'async_trait,
fn complete_json<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: Prompt,
schema: &'life1 Schema,
) -> Pin<Box<dyn Future<Output = Result<Value, TextModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
M: 'async_trait,
Source§fn complete_as<'life0, 'async_trait, T>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<T, TextModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: JsonSchema + DeserializeOwned + Send + 'async_trait,
M: 'async_trait,
fn complete_as<'life0, 'async_trait, T>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<T, TextModelError>> + Send + 'async_trait>>where
'life0: 'async_trait,
T: JsonSchema + DeserializeOwned + Send + 'async_trait,
M: 'async_trait,
prompt and deserializes the conforming value into T,
using T’s own schema (schema_for) as the constraint — the
typed form of TextModelExt::complete_json. Read more