Trait ChatProvider

Source
pub trait ChatProvider: Sync + Send {
    // Required method
    fn chat_with_tools<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        messages: &'life1 [ChatMessage],
        tools: Option<&'life2 [Tool]>,
        json_schema: Option<StructuredOutputFormat>,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn chat<'life0, 'life1, 'async_trait>(
        &'life0 self,
        messages: &'life1 [ChatMessage],
        json_schema: Option<StructuredOutputFormat>,
    ) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn chat_stream<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _messages: &'life1 [ChatMessage],
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String, LLMError>> + Send>>, LLMError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn memory_contents<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn summarize_history<'life0, 'life1, 'async_trait>(
        &'life0 self,
        msgs: &'life1 [ChatMessage],
    ) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Trait for providers that support chat-style interactions.

Required Methods§

Source

fn chat_with_tools<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: &'life1 [ChatMessage], tools: Option<&'life2 [Tool]>, json_schema: Option<StructuredOutputFormat>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Sends a chat request to the provider with a sequence of messages and tools.

§Arguments
  • messages - The conversation history as a slice of chat messages
  • tools - Optional slice of tools to use in the chat
§Returns

The provider’s response text or an error

Provided Methods§

Source

fn chat<'life0, 'life1, 'async_trait>( &'life0 self, messages: &'life1 [ChatMessage], json_schema: Option<StructuredOutputFormat>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn ChatResponse>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends a chat request to the provider with a sequence of messages.

§Arguments
  • messages - The conversation history as a slice of chat messages
§Returns

The provider’s response text or an error

Source

fn chat_stream<'life0, 'life1, 'async_trait>( &'life0 self, _messages: &'life1 [ChatMessage], ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String, LLMError>> + Send>>, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Sends a streaming chat request to the provider with a sequence of messages.

§Arguments
  • messages - The conversation history as a slice of chat messages
§Returns

A stream of text tokens or an error

Source

fn memory_contents<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<Vec<ChatMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get current memory contents if provider supports memory

Source

fn summarize_history<'life0, 'life1, 'async_trait>( &'life0 self, msgs: &'life1 [ChatMessage], ) -> Pin<Box<dyn Future<Output = Result<String, LLMError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Summarizes a conversation history into a concise 2-3 sentence summary

§Arguments
  • msgs - The conversation messages to summarize
§Returns

A string containing the summary or an error if summarization fails

Implementors§