pub struct Chat<M: ModelInfo> {
pub model: M,
pub system_prompt: String,
pub max_output_tokens: usize,
pub history: Vec<Message>,
pub tools: Option<Vec<LlmToolInfo>>,
/* private fields */
}Expand description
The main Chat client that users will interact with. All methods return a new instance rather than mutating the existing one, following the immutable builder pattern.
Fields§
§model: M§system_prompt: String§max_output_tokens: usize§history: Vec<Message>§tools: Option<Vec<LlmToolInfo>>Implementations§
Source§impl<M> Chat<M>where
M: ModelInfo,
impl<M> Chat<M>where
M: ModelInfo,
Sourcepub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
Sets system prompt and returns a new instance
Sourcepub fn with_max_output_tokens(self, n: usize) -> Self
pub fn with_max_output_tokens(self, n: usize) -> Self
Sets max output tokens and returns a new instance
Sourcepub fn with_history(self, history: Vec<Message>) -> Self
pub fn with_history(self, history: Vec<Message>) -> Self
Sets history and returns a new instance
Sourcepub fn with_compactor<C: ChatHistoryCompactor + 'static>(self, comp: C) -> Self
pub fn with_compactor<C: ChatHistoryCompactor + 'static>(self, comp: C) -> Self
Sets compactor and returns a new instance
Sourcepub fn add_message(self, msg: Message) -> Self
pub fn add_message(self, msg: Message) -> Self
Adds a message to the conversation history and returns a new instance
Sourcepub fn push_message(self, msg: Message) -> Self
pub fn push_message(self, msg: Message) -> Self
Alias for add_message for backward compatibility
Sourcepub fn tokens_used(&self) -> usize
pub fn tokens_used(&self) -> usize
Gets the current token count
Sourcepub fn with_tool(self, tool: impl ToolDefinition) -> Result<Self>
pub fn with_tool(self, tool: impl ToolDefinition) -> Result<Self>
Add a tool and returns a new instance with the tool added
Auto Trait Implementations§
impl<M> Freeze for Chat<M>where
M: Freeze,
impl<M> !RefUnwindSafe for Chat<M>
impl<M> !Send for Chat<M>
impl<M> !Sync for Chat<M>
impl<M> Unpin for Chat<M>where
M: Unpin,
impl<M> !UnwindSafe for Chat<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more