Skip to main content

BaseChatModel

Trait BaseChatModel 

Source
pub trait BaseChatModel: BaseLanguageModel<Vec<Message>, LLMResult> {
    // Required methods
    fn chat<'life0, 'async_trait>(
        &'life0 self,
        messages: Vec<Message>,
        config: Option<RunnableConfig>,
    ) -> Pin<Box<dyn Future<Output = Result<LLMResult, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stream_chat<'life0, 'async_trait>(
        &'life0 self,
        messages: Vec<Message>,
        config: Option<RunnableConfig>,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn chat_with_system<'life0, 'async_trait>(
        &'life0 self,
        system: String,
        messages: Vec<Message>,
    ) -> Pin<Box<dyn Future<Output = Result<LLMResult, Self::Error>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

聊天模型基础 trait

继承自 BaseLanguageModel,专门用于聊天场景。 接受消息列表作为输入,返回 AI 消息。

Required Methods§

Source

fn chat<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<LLMResult, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

与模型聊天

§参数
  • messages - 消息列表
  • config - 可选配置
§返回

LLM 结果

Source

fn stream_chat<'life0, 'async_trait>( &'life0 self, messages: Vec<Message>, config: Option<RunnableConfig>, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<String, Self::Error>> + Send>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

流式聊天

§参数
  • messages - 消息列表
  • config - 可选配置
§返回

流式输出

Provided Methods§

Source

fn chat_with_system<'life0, 'async_trait>( &'life0 self, system: String, messages: Vec<Message>, ) -> Pin<Box<dyn Future<Output = Result<LLMResult, Self::Error>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

与系统提示聊天

§参数
  • system - 系统提示
  • messages - 消息列表
§返回

LLM 结果

Implementors§