Skip to main content

LlmProvider

Trait LlmProvider 

Source
pub trait LlmProvider: Send + Sync {
    // Required methods
    fn chat<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 [ToolDef],
    ) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn name(&self) -> &str;
    fn context_window(&self) -> u64;
    fn default_model(&self) -> &str;

    // Provided methods
    fn chat_streaming<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 [ToolDef],
        token_tx: &'life3 UnboundedSender<String>,
    ) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn supports_streaming(&self) -> bool { ... }
}

Required Methods§

Source

fn chat<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [Message], tools: &'life2 [ToolDef], ) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send messages + tool definitions, receive a response.

Source

fn name(&self) -> &str

Human-readable name for this provider.

Source

fn context_window(&self) -> u64

Context window size in tokens.

Source

fn default_model(&self) -> &str

Default model name.

Provided Methods§

Source

fn chat_streaming<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, messages: &'life1 [Message], tools: &'life2 [ToolDef], token_tx: &'life3 UnboundedSender<String>, ) -> Pin<Box<dyn Future<Output = Result<LlmResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Stream text tokens via token_tx while accumulating the full response. The default falls back to chat() and delivers the entire text as one chunk.

Source

fn supports_streaming(&self) -> bool

Whether this provider supports true token-by-token streaming. Providers that override chat_streaming with SSE should return true.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§