Skip to main content

Assistant

Struct Assistant 

Source
pub struct Assistant<LLM: LanguageModel> { /* private fields */ }
Expand description

A struct representing an Assistant that interacts with a language model (LLM), manages a collection of messages, and provides access to various tools.

§Type Parameters

  • LLM: A type that implements the LanguageModel trait, representing the underlying language model used by the Assistant.

§Fields

  • messages: A vector of Message instances representing the conversation history or context.
  • tools: A collection of tools available to the Assistant for performing various tasks.
  • llm: The language model instance used by the Assistant for generating responses or performing language-related tasks.

Implementations§

Source§

impl<LLM: LanguageModel> Assistant<LLM>

Source

pub const fn new(llm: LLM) -> Self

Creates a new Assistant instance with the provided language model.

§Parameters
  • llm: The language model instance to be used by the assistant.
§Returns

Returns a new Assistant with empty messages and tools.

Source

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

Adds a system message to the conversation history.

§Parameters
  • prompt: The system prompt to add as a message.
§Returns

Returns the updated Assistant instance with the system message added.

Source

pub fn tool(self, tool: impl Tool + 'static) -> Result<Self, RegisterError>

Registers a tool with the assistant, making it available for use in interactions.

§Parameters
  • tool: The tool to register with the assistant.
§Errors

Returns RegisterError if a tool of that name is already registered, or the tool has no description for the model to read.

Source

pub async fn send(&mut self, message: impl Into<String>) -> Result<()>

Sends a user message to the assistant, processes it with the language model, and appends the response to the conversation history.

§Parameters
  • message: The user message to send to the assistant.
§Errors

Returns an error if the language model fails to generate a response or if message processing fails.

Source

pub const fn messages(&self) -> &[Message]

Returns a slice of all messages in the conversation history.

Trait Implementations§

Source§

impl<LLM: Debug + LanguageModel> Debug for Assistant<LLM>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<LLM> !RefUnwindSafe for Assistant<LLM>

§

impl<LLM> !UnwindSafe for Assistant<LLM>

§

impl<LLM> Freeze for Assistant<LLM>
where LLM: Freeze,

§

impl<LLM> Send for Assistant<LLM>

§

impl<LLM> Sync for Assistant<LLM>

§

impl<LLM> Unpin for Assistant<LLM>
where LLM: Unpin,

§

impl<LLM> UnsafeUnpin for Assistant<LLM>
where LLM: UnsafeUnpin,

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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.