pub struct RequestDeduplicator { /* private fields */ }Expand description
Deduplicates identical in-flight LLM requests by their content hash.
All methods take &mut self, so wrap in a Mutex or RwLock for
concurrent access.
Implementations§
Source§impl RequestDeduplicator
impl RequestDeduplicator
Sourcepub fn hash_key(model_id: &str, prompt_text: &str) -> String
pub fn hash_key(model_id: &str, prompt_text: &str) -> String
Compute the SHA-256 deduplication key for a given model ID and prompt.
Sourcepub fn submit(
&mut self,
request_id: impl Into<String>,
model_id: &str,
prompt_text: &str,
) -> DedupDecision
pub fn submit( &mut self, request_id: impl Into<String>, model_id: &str, prompt_text: &str, ) -> DedupDecision
Submit a request and decide whether it is the original or a duplicate.
Prunes stale entries (older than 30 s) before processing the new request so that a crashed original does not block future requests with the same key forever.
Sourcepub fn complete(
&mut self,
model_id: &str,
prompt_text: &str,
result: Vec<String>,
) -> usize
pub fn complete( &mut self, model_id: &str, prompt_text: &str, result: Vec<String>, ) -> usize
Signal that the original request identified by model_id +
prompt_text has completed with the given result.
All registered waiters are notified. Returns the number of waiters that were fanned out to.
If no in-flight entry is found (e.g., it was already pruned), returns
0.
Sourcepub fn stats(&self) -> DedupStats
pub fn stats(&self) -> DedupStats
Return current statistics.
Sourcepub fn prune_stale(&mut self)
pub fn prune_stale(&mut self)
Prune in-flight entries older than Self::TTL.
Called automatically by submit; can also be called manually.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Return the number of currently active (in-flight) requests.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RequestDeduplicator
impl !UnwindSafe for RequestDeduplicator
impl Freeze for RequestDeduplicator
impl Send for RequestDeduplicator
impl Sync for RequestDeduplicator
impl Unpin for RequestDeduplicator
impl UnsafeUnpin for RequestDeduplicator
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request