Skip to main content

FailoverPolicy

Trait FailoverPolicy 

Source
pub trait FailoverPolicy: Send + Sync {
    // Required method
    fn after_error(
        &self,
        request: &ModelRequest,
        error: &ProviderError,
        attempt: u32,
        attempts: u32,
    ) -> FailoverAction;

    // Provided methods
    fn prepare_step(&self, _request: &mut ModelRequest) { ... }
    fn before_attempt(
        &self,
        _request: &ModelRequest,
    ) -> Result<(), ProviderError> { ... }
}
Expand description

Decides what follows a failed attempt. The default (DefaultFailover) retries what ProviderError::is_retryable allows on the same step, then moves on; it moves on at once from every other error (another provider may accept what this one refused) and stops only on a context overflow (the caller must shrink the request). A request with crate::RequestOptions::single_attempt stops at its first error whatever the policy says, unless it also sets crate::RequestOptions::fallback_when_unspent and the error proves the attempt used nothing: then it moves on to the next step.

Required Methods§

Source

fn after_error( &self, request: &ModelRequest, error: &ProviderError, attempt: u32, attempts: u32, ) -> FailoverAction

request is what the failed attempt sent; attempt counts from 1; attempts is the step’s limit.

Provided Methods§

Source

fn prepare_step(&self, _request: &mut ModelRequest)

Shape request for this step before its first attempt: it already names the step’s model (FailoverStep::model), so what is only valid for another model (a reasoning signature, an encrypted reasoning item) can be dropped here. Default: leave it as it is.

Source

fn before_attempt(&self, _request: &ModelRequest) -> Result<(), ProviderError>

Whether to send request on this step at all. An error skips the attempt and is handled as its failure (for example, a model the app knows is out of credit). Default: send it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§