Memory

Trait Memory 

Source
pub trait Memory: Send + Sync {
    // Required methods
    fn messages(&self) -> Vec<Message>;
    fn add_message(&mut self, message: Message);
    fn clear(&mut self);

    // Provided methods
    fn add_user_message(&mut self, message: &dyn Display) { ... }
    fn add_ai_message(&mut self, message: &dyn Display) { ... }
    fn to_string(&self) -> String { ... }
}
Expand description

A trait representing a memory storage for messages.

Required Methods§

Source

fn messages(&self) -> Vec<Message>

Returns all messages stored in memory.

Source

fn add_message(&mut self, message: Message)

Adds a message to the memory.

Source

fn clear(&mut self)

Clears all messages from memory.

Provided Methods§

Source

fn add_user_message(&mut self, message: &dyn Display)

Adds a user (human) message to the memory.

Source

fn add_ai_message(&mut self, message: &dyn Display)

Adds an AI (LLM) message to the memory.

Source

fn to_string(&self) -> String

Converts the memory’s messages to a string representation.

Trait Implementations§

Source§

impl<M> From<M> for Box<dyn Memory>
where M: Memory + 'static,

Converts a type implementing Memory into a boxed trait object.

Source§

fn from(memory: M) -> Self

Converts to this type from the input type.

Implementors§