Skip to main content

LlmProvider

Trait LlmProvider 

Source
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§

Source

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.

Source

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.

Source

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.

Source

fn name(&self) -> &'static str

Provider name (“openai” | “anthropic” | “ollama”).

Source

fn model(&self) -> &str

Active default model slug.

Provided Methods§

Source

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".

Implementations on Foreign Types§

Source§

impl<T> LlmProvider for Arc<T>
where T: LlmProvider + ?Sized,

Source§

fn chat<'life0, 'async_trait>( &'life0 self, req: ChatRequest, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Arc<T>: 'async_trait,

Source§

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, Arc<T>: 'async_trait,

Source§

fn embed<'life0, 'async_trait>( &'life0 self, req: EmbedRequest, ) -> Pin<Box<dyn Future<Output = Result<EmbedResponse, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Arc<T>: 'async_trait,

Source§

fn name(&self) -> &'static str

Source§

fn model(&self) -> &str

Source§

fn estimate_cost(&self, req: &ChatRequest) -> Option<CostEstimate>

Implementors§