Trait CreateChatSession

Source
pub trait CreateChatSession {
    type Error: Send + Sync + 'static;
    type ChatSession: ChatSession;

    // Required method
    fn new_chat_session(&self) -> Result<Self::ChatSession, Self::Error>;
}
Expand description

A trait for creating a chat session. While it the core trait every chat session implementation implements, most methods to use models that implement this trait are implemented in the ChatModelExt trait.

§Example

use kalosm::language::*;

#[tokio::main]
async fn main() {
    // Create a new model which implements the CreateChatSession trait
    let llm = Llama::new_chat().await.unwrap();
    // Create a new chat for the model
    let mut chat = llm.chat();
    // Add a message to the chat session
    chat("Hello, world!").to_std_out().await.unwrap();
}

Required Associated Types§

Source

type Error: Send + Sync + 'static

The type of error the chat session may return during operations.

Source

type ChatSession: ChatSession

The type of chat session.

Required Methods§

Source

fn new_chat_session(&self) -> Result<Self::ChatSession, Self::Error>

Create a new chat session for this model.

§Example
use kalosm::language::*;

#[tokio::main]
async fn main() {
    // Create a new model which implements the CreateChatSession trait
    let llm = Llama::new_chat().await.unwrap();
    // Create a new chat session for the model
    let mut chat_session = llm.new_chat_session().unwrap();
}

Implementors§