Skip to main content

ChatClient

Trait ChatClient 

Source
pub trait ChatClient: Send + Sync {
    // Required methods
    fn get_response<'life0, 'async_trait>(
        &'life0 self,
        messages: Vec<Message>,
        options: ChatOptions,
    ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn get_streaming_response<'life0, 'async_trait>(
        &'life0 self,
        messages: Vec<Message>,
        options: ChatOptions,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatResponseUpdate, Error>> + Send>>, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn model(&self) -> Option<&str> { ... }
    fn service_url(&self) -> Option<&str> { ... }
}
Expand description

The interface every chat client implements.

Implementors provide ChatClient::get_response and ChatClient::get_streaming_response; the framework layers tool invocation and middleware on top via FunctionInvokingChatClient.

Required Methods§

Source

fn get_response<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, options: ChatOptions, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Get a complete (non-streaming) response.

Source

fn get_streaming_response<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, options: ChatOptions, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatResponseUpdate, Error>> + Send>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Get a streaming response as a sequence of updates.

Provided Methods§

Source

fn model(&self) -> Option<&str>

The default model id for this client, if any.

Source

fn service_url(&self) -> Option<&str>

The endpoint this client sends requests to, if it has one.

Recorded as server.address on the chat span by ObservableChatClient, so traces show which deployment served a call — two clients for the same provider and model pointed at different hosts are otherwise indistinguishable. Wrappers forward their inner client’s value. Mirrors upstream’s service_url() (#9225, #9222).

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> ChatClient for Arc<T>
where T: ChatClient + ?Sized,

Blanket impl so Arc<dyn ChatClient> and wrappers are usable as clients.

Source§

fn get_response<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, options: ChatOptions, ) -> Pin<Box<dyn Future<Output = Result<ChatResponse, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Arc<T>: 'async_trait,

Source§

fn get_streaming_response<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, options: ChatOptions, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<ChatResponseUpdate, Error>> + Send>>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Arc<T>: 'async_trait,

Source§

fn model(&self) -> Option<&str>

Source§

fn service_url(&self) -> Option<&str>

Implementors§