pub struct SessionOptimizer {
pub cache: ResponseCache,
pub dedup: DedupTracker,
pub config: ResponseOptimizerConfig,
pub stats: OptimizerStats,
}Expand description
Per-session optimizer state. Each session/conversation gets its own instance.
Fields§
§cache: ResponseCache§dedup: DedupTracker§config: ResponseOptimizerConfig§stats: OptimizerStatsImplementations§
Source§impl SessionOptimizer
impl SessionOptimizer
pub fn new(config: ResponseOptimizerConfig) -> Self
Sourcepub fn try_cache_hit(&mut self, cache_key: u64) -> Option<&str>
pub fn try_cache_hit(&mut self, cache_key: u64) -> Option<&str>
Check if a request can be served from cache. Returns the cached response body if available.
Sourcepub fn record_response(
&mut self,
cache_key: u64,
response: &str,
output_tokens: u64,
) -> OptimizationDecision
pub fn record_response( &mut self, cache_key: u64, response: &str, output_tokens: u64, ) -> OptimizationDecision
Record a response for future cache lookups and dedup detection.
Sourcepub fn cache_hit_decision(
&self,
cache_key: u64,
tokens_saved: u64,
) -> OptimizationDecision
pub fn cache_hit_decision( &self, cache_key: u64, tokens_saved: u64, ) -> OptimizationDecision
Build a decision record for a cache hit.
Trait Implementations§
Auto Trait Implementations§
impl Forget for SessionOptimizer
impl Freeze for SessionOptimizer
impl Move for SessionOptimizer
impl RefUnwindSafe for SessionOptimizer
impl Send for SessionOptimizerwhere
RawVecInner: Send,
impl Sync for SessionOptimizerwhere
RawVecInner: Sync,
impl Unpin for SessionOptimizer
impl UnsafeUnpin for SessionOptimizerwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<(u64, CacheEntry)>: UnsafeUnpin,
PhantomData<u64>: UnsafeUnpin,
impl UnwindSafe for SessionOptimizerwhere
RawVecInner: UnwindSafe,
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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