pub struct SessionManager { /* private fields */ }Expand description
High-level session management
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub async fn add_user_message(
&self,
session_id: &str,
query: &str,
config: CompilerConfig,
index: &VectorIndex,
api_key: Option<&str>,
) -> Result<(Message, WorkingSet)>
pub async fn add_user_message( &self, session_id: &str, query: &str, config: CompilerConfig, index: &VectorIndex, api_key: Option<&str>, ) -> Result<(Message, WorkingSet)>
Add a user message and compile context
This method:
- Adds the user message to the database
- Calls the compiler to generate a WorkingSet from the query
- Associates the WorkingSet with the session
- Returns both the Message and WorkingSet
§Arguments
session_id- The session IDquery- The user’s queryconfig- Compiler configurationindex- Vector index for searchapi_key- Optional OpenAI API key (for embeddings)
§Returns
Tuple of (Message, WorkingSet)
Sourcepub fn add_assistant_message(
&self,
session_id: &str,
content: &str,
metadata: Option<&Value>,
) -> Result<Message>
pub fn add_assistant_message( &self, session_id: &str, content: &str, metadata: Option<&Value>, ) -> Result<Message>
Sourcepub fn get_conversation_history(
&self,
session_id: &str,
max_tokens: Option<usize>,
) -> Result<String>
pub fn get_conversation_history( &self, session_id: &str, max_tokens: Option<usize>, ) -> Result<String>
Get conversation history formatted for LLM consumption
Formats messages as:
User: <message>
Assistant: <message>
User: <message>
...If max_tokens is specified, older messages are truncated to stay within
the token budget. Most recent messages are always kept (they’re most relevant).
§Arguments
session_id- The session IDmax_tokens- Optional token limit
§Returns
Formatted conversation history as a string
Sourcepub fn replay_session(&self, session_id: &str) -> Result<SessionReplay>
pub fn replay_session(&self, session_id: &str) -> Result<SessionReplay>
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> 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