Skip to main content

ChatProvider

Trait ChatProvider 

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

    // Provided methods
    fn chat_stream<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 [ToolSpec],
        on_delta: DeltaFn<'life3>,
    ) -> Pin<Box<dyn Future<Output = Result<Message>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn chat_stream_patched<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        messages: &'life1 [Message],
        tools: &'life2 [ToolSpec],
        on_delta: DeltaFn<'life3>,
        patch: &'life4 RequestPatch,
    ) -> Pin<Box<dyn Future<Output = Result<Message>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait { ... }
    fn take_usage(&self) -> Option<TurnUsage> { ... }
    fn can_see(&self) -> bool { ... }
}

Required Methods§

Source

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

Send the conversation and return the assistant’s reply (text and/or tool calls).

Provided Methods§

Source

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

Like chat, but reports assistant text through on_delta as it is generated. The returned message is always the complete reply. Providers that cannot stream just answer normally and emit no deltas.

Source

fn chat_stream_patched<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, messages: &'life1 [Message], tools: &'life2 [ToolSpec], on_delta: DeltaFn<'life3>, patch: &'life4 RequestPatch, ) -> Pin<Box<dyn Future<Output = Result<Message>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

One streaming turn with a request patch applied.

The default refuses a non-empty patch instead of dropping it: a hook that set tool_choice and a provider that ignored it would make the model look irrational for a reason nothing in the transcript records.

Source

fn take_usage(&self) -> Option<TurnUsage>

What the most recent call cost, if the server said. Taken rather than borrowed so a caller cannot show the same turn twice; providers that do not measure return None.

Source

fn can_see(&self) -> bool

Whether this provider’s manifest claims it can read a picture (#346).

false by default, which is the honest answer for anything that is not an OpenAI-compatible client with a profile: a test double or an embedder cannot see, and [vision] mode = "native" against one refuses the attach instead of sending bytes into a void.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§