pub struct ConversationSession {
pub id: ConversationId,
pub user_id: Option<String>,
pub system_prompt: Option<String>,
pub messages: Vec<ChatMessage>,
pub turns: Vec<Turn>,
pub state: SessionState,
pub created_at: u64,
pub updated_at: u64,
pub metadata: HashMap<String, String>,
/* private fields */
}Expand description
A session representing a conversation
Fields§
§id: ConversationIdSession ID
user_id: Option<String>User ID (if applicable)
system_prompt: Option<String>System prompt
messages: Vec<ChatMessage>Message history
turns: Vec<Turn>Conversation turns
state: SessionStateSession state
created_at: u64When session was created
updated_at: u64When session was last updated
metadata: HashMap<String, String>Session metadata
Implementations§
Source§impl ConversationSession
impl ConversationSession
pub fn new(id: impl Into<String>) -> Self
pub fn with_config(self, config: SessionConfig) -> Self
pub fn with_user_id(self, user_id: impl Into<String>) -> Self
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Sourcepub fn add_message(&mut self, role: ChatRole, content: impl Into<String>)
pub fn add_message(&mut self, role: ChatRole, content: impl Into<String>)
Add a message to the session
Sourcepub fn add_message_obj(&mut self, message: ChatMessage)
pub fn add_message_obj(&mut self, message: ChatMessage)
Add a pre-constructed message
Sourcepub fn get_context(&self, max_tokens: Option<usize>) -> Vec<&ChatMessage>
pub fn get_context(&self, max_tokens: Option<usize>) -> Vec<&ChatMessage>
Get messages for context (within token limit)
Sourcepub fn get_all_messages(&self) -> &[ChatMessage]
pub fn get_all_messages(&self) -> &[ChatMessage]
Get all messages
Sourcepub fn get_recent(&self, n: usize) -> Vec<&ChatMessage>
pub fn get_recent(&self, n: usize) -> Vec<&ChatMessage>
Get recent N messages
Sourcepub fn get_by_role(&self, role: ChatRole) -> Vec<&ChatMessage>
pub fn get_by_role(&self, role: ChatRole) -> Vec<&ChatMessage>
Get messages by role
Sourcepub fn current_turn(&self) -> u32
pub fn current_turn(&self) -> u32
Get current turn number
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if session is expired
Sourcepub fn clear_messages(&mut self)
pub fn clear_messages(&mut self)
Clear all messages (keep system prompt)
Sourcepub fn total_tokens(&self) -> usize
pub fn total_tokens(&self) -> usize
Get total estimated tokens
Trait Implementations§
Source§impl Clone for ConversationSession
impl Clone for ConversationSession
Source§fn clone(&self) -> ConversationSession
fn clone(&self) -> ConversationSession
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 ConversationSession
impl Debug for ConversationSession
Source§impl<'de> Deserialize<'de> for ConversationSession
impl<'de> Deserialize<'de> for ConversationSession
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ConversationSession
impl RefUnwindSafe for ConversationSession
impl Send for ConversationSession
impl Sync for ConversationSession
impl Unpin for ConversationSession
impl UnsafeUnpin for ConversationSession
impl UnwindSafe for ConversationSession
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