pub struct SessionManager { /* private fields */ }Expand description
Thread-safe store for active Session objects.
Session IDs are generated from a monotonically increasing counter combined with a timestamp so they are unique and roughly sortable by creation time.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn create_session(&self, model: &str, max_context: usize) -> String
pub fn create_session(&self, model: &str, max_context: usize) -> String
Create a new session for model with the given context-token limit.
Returns the new session ID.
Sourcepub fn get_context(&self, session_id: &str) -> Option<Vec<Message>>
pub fn get_context(&self, session_id: &str) -> Option<Vec<Message>>
Return a snapshot of the messages currently held in the session, or
None if the session does not exist.
Sourcepub fn add_turn(
&self,
session_id: &str,
user_msg_tokens: usize,
assistant_msg_tokens: usize,
)
pub fn add_turn( &self, session_id: &str, user_msg_tokens: usize, assistant_msg_tokens: usize, )
Append a user turn and an assistant turn to the session.
user_msg_tokens and assistant_msg_tokens carry placeholder content
strings; callers that need real content should use
Session::add_message directly after obtaining a write lock.
Sourcepub fn expire_sessions(&self, timeout_secs: u64) -> usize
pub fn expire_sessions(&self, timeout_secs: u64) -> usize
Remove sessions that have been inactive for longer than timeout_secs.
Returns the number of sessions removed.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Return the number of active sessions.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionManager
impl RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request