Struct Chat

Source
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,

Source

pub fn new(model: M) -> Self

Creates a new Chat instance with a model and provider

Source

pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self

Sets system prompt and returns a new instance

Source

pub fn with_max_output_tokens(self, n: usize) -> Self

Sets max output tokens and returns a new instance

Source

pub fn with_history(self, history: Vec<Message>) -> Self

Sets history and returns a new instance

Source

pub fn with_compactor<C: ChatHistoryCompactor + 'static>(self, comp: C) -> Self

Sets compactor and returns a new instance

Source

pub fn add_message(self, msg: Message) -> Self

Adds a message to the conversation history and returns a new instance

Source

pub fn push_message(self, msg: Message) -> Self

Alias for add_message for backward compatibility

Source

pub fn tokens_used(&self) -> usize

Gets the current token count

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T