pub struct FailoverChain { /* private fields */ }Expand description
A priority-ordered chain of model workers with automatic failover.
Workers are tried in insertion order. Unhealthy workers (as determined by
the ProviderHealthMonitor) are skipped without consuming an attempt
slot. The max_attempts limit counts only actual inference attempts
(i.e. workers that were healthy and returned a result — success or failure).
Implementations§
Source§impl FailoverChain
impl FailoverChain
Sourcepub fn new(health: ProviderHealthMonitor) -> Self
pub fn new(health: ProviderHealthMonitor) -> Self
Sourcepub fn add_worker(
self,
provider_id: impl Into<String>,
worker: Arc<dyn ModelWorker>,
) -> Self
pub fn add_worker( self, provider_id: impl Into<String>, worker: Arc<dyn ModelWorker>, ) -> Self
Append a worker to the end of the chain.
Workers are tried in the order they are added.
§Panics
Never panics.
Sourcepub fn with_max_attempts(self, n: usize) -> Self
pub fn with_max_attempts(self, n: usize) -> Self
Override the maximum number of attempted inferences before the chain
gives up. Defaults to 3. A value of 0 is silently raised to 1.
§Panics
Never panics.
Sourcepub async fn infer(
&self,
prompt: &str,
) -> Result<(String, String), OrchestratorError>
pub async fn infer( &self, prompt: &str, ) -> Result<(String, String), OrchestratorError>
Run inference through the chain.
Workers are tried in priority order. For each candidate:
- The health monitor is consulted; unhealthy providers are skipped
(they do not count against
max_attempts). - The worker’s
ModelWorker::infermethod is called. - On success the outcome is recorded with the health monitor and the
(provider_id, response_text)tuple is returned. - On failure the outcome is recorded and the next candidate is tried
(unless
max_attemptshas been exhausted).
Returns Err(OrchestratorError::Inference) if all candidates fail or
the chain is empty.
§Panics
Never panics.
Auto Trait Implementations§
impl !RefUnwindSafe for FailoverChain
impl !UnwindSafe for FailoverChain
impl Freeze for FailoverChain
impl Send for FailoverChain
impl Sync for FailoverChain
impl Unpin for FailoverChain
impl UnsafeUnpin for FailoverChain
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