pub trait ChatProvider: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn model(&self) -> &str;
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<ChatMessage>,
tools: Vec<ToolDef>,
tx: Sender<ChatEvent>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Streaming chat provider abstraction.
Why: downstream crates (trusty-memory, trusty-search) want to support
multiple LLM backends without hard-coding which one to call. Providers
expose a uniform streaming interface so the caller can swap them at
runtime based on configuration / availability.
What: implementors stream ChatEvents into tx. Pass an empty
tools vec to disable tool use entirely (the provider MUST then omit
the tools field from the upstream request — some models error on an
empty array). Returning Ok(()) means the stream completed normally;
the caller should also expect a final ChatEvent::Done.
Test: implementations are covered by their own unit tests in this
module plus integration tests in downstream crates.
Required Methods§
Sourcefn chat_stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<ChatMessage>,
tools: Vec<ToolDef>,
tx: Sender<ChatEvent>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
messages: Vec<ChatMessage>,
tools: Vec<ToolDef>,
tx: Sender<ChatEvent>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stream chat events into tx. tools empty disables tool use.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".