pub struct PersistenceContext<S>{ /* private fields */ }Expand description
持久化上下文
提供对持久化功能的便捷访问
Implementations§
Source§impl<S> PersistenceContext<S>
impl<S> PersistenceContext<S>
Sourcepub async fn new(
store: Arc<S>,
user_id: Uuid,
tenant_id: Uuid,
agent_id: Uuid,
) -> Result<PersistenceContext<S>, LLMError>
pub async fn new( store: Arc<S>, user_id: Uuid, tenant_id: Uuid, agent_id: Uuid, ) -> Result<PersistenceContext<S>, LLMError>
创建新的持久化上下文
Sourcepub fn from_session(
store: Arc<S>,
user_id: Uuid,
agent_id: Uuid,
tenant_id: Uuid,
session_id: Uuid,
) -> PersistenceContext<S>
pub fn from_session( store: Arc<S>, user_id: Uuid, agent_id: Uuid, tenant_id: Uuid, session_id: Uuid, ) -> PersistenceContext<S>
从现有会话创建上下文
Sourcepub fn session_id(&self) -> Uuid
pub fn session_id(&self) -> Uuid
获取会话 ID
Sourcepub async fn save_user_message(
&self,
content: impl Into<String>,
) -> Result<Uuid, LLMError>
pub async fn save_user_message( &self, content: impl Into<String>, ) -> Result<Uuid, LLMError>
保存用户消息
Sourcepub async fn save_assistant_message(
&self,
content: impl Into<String>,
) -> Result<Uuid, LLMError>
pub async fn save_assistant_message( &self, content: impl Into<String>, ) -> Result<Uuid, LLMError>
保存助手消息
Sourcepub async fn get_history(&self) -> Result<Vec<LLMMessage>, LLMError>
pub async fn get_history(&self) -> Result<Vec<LLMMessage>, LLMError>
获取会话消息历史
Sourcepub async fn get_usage_stats(&self) -> Result<UsageStatistics, LLMError>
pub async fn get_usage_stats(&self) -> Result<UsageStatistics, LLMError>
获取使用统计
Sourcepub async fn new_session(&mut self) -> Result<Uuid, LLMError>
pub async fn new_session(&mut self) -> Result<Uuid, LLMError>
创建新会话
Auto Trait Implementations§
impl<S> Freeze for PersistenceContext<S>
impl<S> RefUnwindSafe for PersistenceContext<S>where
S: RefUnwindSafe,
impl<S> Send for PersistenceContext<S>
impl<S> Sync for PersistenceContext<S>
impl<S> Unpin for PersistenceContext<S>
impl<S> UnsafeUnpin for PersistenceContext<S>
impl<S> UnwindSafe for PersistenceContext<S>where
S: 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 moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage