pub struct SessionManager { /* private fields */ }Expand description
Concurrent, lock-free store of Sessions keyed by u64 ID.
All methods are &self and safe to call from multiple Tokio tasks.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn create(&self, system_prompt: Option<String>) -> u64
pub fn create(&self, system_prompt: Option<String>) -> u64
Create a new session, optionally pre-loading a system message.
Returns the new session’s ID.
Sourcepub fn append(
&self,
session_id: u64,
role: Role,
content: String,
) -> Result<(), SessionError>
pub fn append( &self, session_id: u64, role: Role, content: String, ) -> Result<(), SessionError>
Append a message to an existing session.
Token count is estimated as word count when not supplied.
Sourcepub fn get(&self, session_id: u64) -> Result<Session, SessionError>
pub fn get(&self, session_id: u64) -> Result<Session, SessionError>
Return a copy of the session, or Err(SessionError::NotFound).
Sourcepub fn get_context(
&self,
session_id: u64,
max_tokens: usize,
) -> Result<Vec<Message>, SessionError>
pub fn get_context( &self, session_id: u64, max_tokens: usize, ) -> Result<Vec<Message>, SessionError>
Return messages for a session trimmed to fit within max_tokens.
Strategy:
- The system message (if any) is always retained.
- Non-system messages are trimmed from the oldest end until the
total fits within
max_tokens.
Sourcepub fn summarize_if_needed(
&self,
session_id: u64,
threshold_tokens: usize,
summarizer: &dyn Fn(&str) -> String,
) -> Result<(), SessionError>
pub fn summarize_if_needed( &self, session_id: u64, threshold_tokens: usize, summarizer: &dyn Fn(&str) -> String, ) -> Result<(), SessionError>
If the session’s total tokens exceed threshold_tokens, call
summarizer on the oldest non-system messages and replace them with a
single assistant summary message.
Sourcepub fn stats(&self) -> SessionStats
pub fn stats(&self) -> SessionStats
Collect aggregate statistics across all stored sessions.
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 (const: unstable) · 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 !RefUnwindSafe for SessionManager
impl !UnwindSafe for SessionManager
impl Freeze for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
Wrap the input message
T in a tonic::Request