pub struct SessionManager {
pub messages: Vec<Message>,
pub max_messages: usize,
pub system_message: Option<Message>,
}
Expand description
Manages the conversation session with history of messages
Fields§
§messages: Vec<Message>
History of messages for the current session
max_messages: usize
Maximum number of messages to keep in the session
system_message: Option<Message>
System message to prepend to all conversations
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(max_messages: usize) -> Self
pub fn new(max_messages: usize) -> Self
Create a new session manager with a specific message capacity
Sourcepub fn with_system_message(self, content: String) -> Self
pub fn with_system_message(self, content: String) -> Self
Add a system message that will be prepended to the conversation
Sourcepub fn add_user_message(&mut self, content: String)
pub fn add_user_message(&mut self, content: String)
Add a user message to the conversation
Sourcepub fn add_assistant_message(&mut self, content: String)
pub fn add_assistant_message(&mut self, content: String)
Add an assistant message to the conversation
Sourcepub fn add_message(&mut self, message: Message)
pub fn add_message(&mut self, message: Message)
Add a message to the conversation
Sourcepub fn replace_with_summary(&mut self, summary: String)
pub fn replace_with_summary(&mut self, summary: String)
Replace all messages with a single summary message
Sourcepub fn get_messages_for_api(&self) -> Vec<Message>
pub fn get_messages_for_api(&self) -> Vec<Message>
Get all messages for the API call, including the system message if present
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
Get the current number of messages
Trait Implementations§
Source§impl Clone for SessionManager
impl Clone for SessionManager
Source§fn clone(&self) -> SessionManager
fn clone(&self) -> SessionManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SessionManager
impl Debug for SessionManager
Auto Trait Implementations§
impl Freeze for SessionManager
impl RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnwindSafe for SessionManager
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more