pub trait ChatProvider: Send + Sync {
// Required methods
fn chat<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn provider_name(&self) -> &'static str;
fn default_model(&self) -> &str;
// Provided methods
fn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn supports_streaming(&self) -> bool { ... }
fn supports_tools(&self) -> bool { ... }
fn supports_vision(&self) -> bool { ... }
fn supports_json_mode(&self) -> bool { ... }
}Expand description
Trait for providers that support chat completions.
This is the primary trait that all LLM backends must implement to support chat-based interactions with language models.
Required Methods§
Sourcefn chat<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Get the name of this provider.
Used for error messages and logging.
Sourcefn default_model(&self) -> &str
fn default_model(&self) -> &str
Get the default model for this provider.
Provided Methods§
Sourcefn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn chat_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Send a chat completion request and receive a streaming response.
This method returns a stream of StreamChunk values that can be processed
as they arrive, enabling real-time display of generated content.
§Arguments
request- The chat request (thestreamfield will be set automatically)
§Returns
A stream of StreamChunk values, or an error if the request fails.
§Default Implementation
By default, this method returns an error indicating streaming is not supported. Providers should override this if they support streaming.
Sourcefn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Check if this provider supports streaming.
Sourcefn supports_tools(&self) -> bool
fn supports_tools(&self) -> bool
Check if this provider supports tool/function calling.
Sourcefn supports_vision(&self) -> bool
fn supports_vision(&self) -> bool
Check if this provider supports vision (image inputs).
Sourcefn supports_json_mode(&self) -> bool
fn supports_json_mode(&self) -> bool
Check if this provider supports JSON mode / structured outputs.