pub struct SessionManagerGeneric<B: StorageBackend> { /* private fields */ }Expand description
Backend-agnostic session manager
This is the generic version of SessionManager that works with any
StorageBackend implementation (SQLite, PostgreSQL, etc.)
§Example
ⓘ
use avocado_core::storage::SqliteBackend;
use avocado_core::session::SessionManagerGeneric;
let backend = SqliteBackend::new("db.sqlite").await?;
let manager = SessionManagerGeneric::new(backend);
let session = manager.start_session(None).await?;Implementations§
Source§impl<B: StorageBackend> SessionManagerGeneric<B>
impl<B: StorageBackend> SessionManagerGeneric<B>
Sourcepub async fn add_user_message(
&self,
session_id: &str,
query: &str,
config: CompilerConfig,
api_key: Option<&str>,
) -> Result<(Message, WorkingSet)>
pub async fn add_user_message( &self, session_id: &str, query: &str, config: CompilerConfig, 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 configurationapi_key- Optional OpenAI API key (for embeddings)
§Returns
Tuple of (Message, WorkingSet)
Sourcepub async fn add_user_message_with_explain(
&self,
session_id: &str,
query: &str,
config: CompilerConfig,
api_key: Option<&str>,
explain: bool,
) -> Result<(Message, WorkingSet)>
pub async fn add_user_message_with_explain( &self, session_id: &str, query: &str, config: CompilerConfig, api_key: Option<&str>, explain: bool, ) -> Result<(Message, WorkingSet)>
Add a user message with explain option
Sourcepub async fn add_assistant_message(
&self,
session_id: &str,
content: &str,
metadata: Option<&Value>,
) -> Result<Message>
pub async fn add_assistant_message( &self, session_id: &str, content: &str, metadata: Option<&Value>, ) -> Result<Message>
Sourcepub async fn get_conversation_history(
&self,
session_id: &str,
max_tokens: Option<usize>,
) -> Result<String>
pub async fn get_conversation_history( &self, session_id: &str, max_tokens: Option<usize>, ) -> Result<String>
Sourcepub async fn replay_session(&self, session_id: &str) -> Result<SessionReplay>
pub async fn replay_session(&self, session_id: &str) -> Result<SessionReplay>
Sourcepub async fn list_sessions(
&self,
user_id: Option<&str>,
limit: Option<usize>,
) -> Result<Vec<Session>>
pub async fn list_sessions( &self, user_id: Option<&str>, limit: Option<usize>, ) -> Result<Vec<Session>>
List sessions
Sourcepub async fn delete_session(&self, session_id: &str) -> Result<()>
pub async fn delete_session(&self, session_id: &str) -> Result<()>
Delete a session
Auto Trait Implementations§
impl<B> Freeze for SessionManagerGeneric<B>
impl<B> RefUnwindSafe for SessionManagerGeneric<B>where
B: RefUnwindSafe,
impl<B> Send for SessionManagerGeneric<B>
impl<B> Sync for SessionManagerGeneric<B>
impl<B> Unpin for SessionManagerGeneric<B>
impl<B> UnwindSafe for SessionManagerGeneric<B>where
B: RefUnwindSafe,
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