pub trait LlmProvider:
Send
+ Sync
+ 'static {
// Required methods
fn chat<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LlmError>> + Send>>, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn embed<'life0, 'async_trait>(
&'life0 self,
req: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn name(&self) -> &'static str;
fn model(&self) -> &str;
// Provided method
fn estimate_cost(&self, _req: &ChatRequest) -> Option<CostEstimate> { ... }
}Expand description
A unified, async LLM backend.
Implemented by each provider adapter (OpenAI, Anthropic, Ollama) and by the Tower-wrapped client, so middleware and fallback chains compose transparently.
Required Methods§
Sourcefn chat<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn chat<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Single-shot chat completion.
Sourcefn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LlmError>> + Send>>, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn chat_stream<'life0, 'async_trait>(
&'life0 self,
req: ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamDelta, LlmError>> + Send>>, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Streaming chat completion.
Sourcefn embed<'life0, 'async_trait>(
&'life0 self,
req: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn embed<'life0, 'async_trait>(
&'life0 self,
req: EmbedRequest,
) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Generate embeddings.
Provided Methods§
Sourcefn estimate_cost(&self, _req: &ChatRequest) -> Option<CostEstimate>
fn estimate_cost(&self, _req: &ChatRequest) -> Option<CostEstimate>
Pre-flight cost estimate (no network call). None if unknown.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".