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 method
    fn model(&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.

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>

Implementors§