Skip to main content

LlmProvider

Trait LlmProvider 

Source
pub trait LlmProvider: Send + Sync {
    // Required method
    fn complete<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 [ToolSpec],
    ) -> Pin<Box<dyn Future<Output = Result<Completion>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn complete_with_search<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        eager_tools: &'life2 [(ToolSpec, Option<String>)],
        deferred_tools: &'life3 [(ToolSpec, Option<String>)],
    ) -> Pin<Box<dyn Future<Output = Result<Completion>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn complete_structured<'life0, 'async_trait>(
        &'life0 self,
        _req: StructuredRequest,
    ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn stream<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 [ToolSpec],
        stream_tx: Option<StreamSender>,
    ) -> Pin<Box<dyn Future<Output = Result<Completion>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn complete_simple<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prompt: &'life1 str,
        _temperature: f32,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}

Required Methods§

Source

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

Provided Methods§

Variant that accepts a partition between eager and deferred tools. Providers that support native deferred loading (e.g. Anthropic via defer_loading: true + tool_reference content blocks) override this. The default implementation concatenates the two lists (dropping the hints) and calls complete() — i.e., it ignores the partition and behaves identically to the legacy interface.

Providers that do NOT support deferred tool loading (e.g. the OpenAI provider) inherit this default and see every tool as eager. No code change is required in those providers.

Source

fn complete_structured<'life0, 'async_trait>( &'life0 self, _req: StructuredRequest, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Request a JSON response conforming to a caller-supplied schema. Default impl returns an error. Providers that support structured output (e.g. OpenAI-compatible) override this.

Source

fn stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [Message], tools: &'life2 [ToolSpec], stream_tx: Option<StreamSender>, ) -> Pin<Box<dyn Future<Output = Result<Completion>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stream a completion token-by-token.

The default implementation delegates to LlmProvider::complete and emits the entire content as a single delta via the channel (if configured). Providers that support native SSE streaming should override this.

The stream_tx channel receives partial-token deltas as they are parsed. The returned Completion is the fully accumulated result.

Source

fn complete_simple<'life0, 'life1, 'async_trait>( &'life0 self, prompt: &'life1 str, _temperature: f32, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Simple completion with a single user prompt.

Wraps the prompt in a user Message and calls complete with no tools. Providers that support temperature or other controls should override this method. The default implementation ignores temperature.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§