pub trait TextModel: Send + Sync {
// Required method
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;
// Provided methods
fn stream<'a>(
&'a self,
prompt: &'a Prompt,
) -> BoxStream<'a, Result<TextDelta, TextModelError>> { ... }
fn supports(&self, _tier: ModelTier, _capability: Capability) -> bool { ... }
}Expand description
Completes a prompt, over whichever provider the venture wired for the
Prompt::tier it was asked for. An adapter serves any tier it is
configured for (typically one); RoutingTextModel dispatches between
the adapters a venture configured.
Required Methods§
Sourcefn 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,
Completes prompt.
Prompt::json_schema is a request: an adapter whose provider
cannot honour structured output answers with plain text in
Completion::text and None in Completion::json, rather than
failing the call.
Provided Methods§
Sourcefn stream<'a>(
&'a self,
prompt: &'a Prompt,
) -> BoxStream<'a, Result<TextDelta, TextModelError>>
fn stream<'a>( &'a self, prompt: &'a Prompt, ) -> BoxStream<'a, Result<TextDelta, TextModelError>>
Streams 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).
§Cancellation
Dropping the returned stream cancels the completion: an overriding
adapter MUST abort its upstream exchange on drop, the same
contract
HttpClient::send_streaming
carries, so a route whose client disconnects stops the spend. A
route handler that needs a 'static stream builds one with
stream_owned.
A successful stream ends with exactly one TextDelta::Finish;
an Err item ends it instead, and no Finish follows an error.
Sourcefn supports(&self, _tier: ModelTier, _capability: Capability) -> bool
fn supports(&self, _tier: ModelTier, _capability: Capability) -> bool
Whether this adapter can do 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.
tier is the router’s own routing key, not the adapter’s: an
adapter serves whatever tier it was wired for and is free to ignore
it — an adapter only honours tier if the same deployment could be
wired for two tiers with different capabilities. The parameter is
on the method so a caller never has to ask the router which model a
tier holds just to ask what it can do.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".