pub struct ConversationFallback { /* private fields */ }Expand description
Conversation fallback manager
Maintains cached conversation contexts to provide fallback responses during circuit breaker outages.
Implementations§
Source§impl ConversationFallback
impl ConversationFallback
Sourcepub fn with_config(default_ttl: Duration, max_contexts: usize) -> Self
pub fn with_config(default_ttl: Duration, max_contexts: usize) -> Self
Create with custom configuration
Sourcepub fn update_context(
&self,
conversation_id: &str,
query: impl Into<String>,
result: impl Into<String>,
)
pub fn update_context( &self, conversation_id: &str, query: impl Into<String>, result: impl Into<String>, )
Update context for a conversation
Sourcepub fn get_fallback(&self, conversation_id: &str) -> Option<ConversationContext>
pub fn get_fallback(&self, conversation_id: &str) -> Option<ConversationContext>
Get fallback for a conversation
Sourcepub fn execute_with_fallback<T, E>(
&self,
conversation_id: &str,
execute: impl FnOnce() -> Result<T, E>,
fallback: impl FnOnce(&ConversationContext) -> T,
) -> Result<T, E>where
E: Display,
pub fn execute_with_fallback<T, E>(
&self,
conversation_id: &str,
execute: impl FnOnce() -> Result<T, E>,
fallback: impl FnOnce(&ConversationContext) -> T,
) -> Result<T, E>where
E: Display,
Execute with fallback on error
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Cleanup expired contexts
Sourcepub fn remove(&self, conversation_id: &str) -> Option<ConversationContext>
pub fn remove(&self, conversation_id: &str) -> Option<ConversationContext>
Remove specific conversation
Sourcepub fn cached_count(&self) -> usize
pub fn cached_count(&self) -> usize
Get number of cached contexts
Sourcepub fn set_default_ttl(&self, ttl: Duration)
pub fn set_default_ttl(&self, ttl: Duration)
Set default TTL
Sourcepub fn has_context(&self, conversation_id: &str) -> bool
pub fn has_context(&self, conversation_id: &str) -> bool
Check if conversation has cached context
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ConversationFallback
impl !RefUnwindSafe for ConversationFallback
impl Send for ConversationFallback
impl Sync for ConversationFallback
impl Unpin for ConversationFallback
impl UnsafeUnpin for ConversationFallback
impl UnwindSafe for ConversationFallback
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