Skip to main content

FallbackChain

Struct FallbackChain 

Source
pub struct FallbackChain<I, O> { /* private fields */ }
Expand description

Ordered list of LLM providers to try in sequence.

Each provider is a (name, callable) pair. call tries them in order until one returns Ok. Returns a ChainResult describing what won and what failed. If every provider returns Err, an AllProvidersFailed error is returned.

Implementations§

Source§

impl<I, O> FallbackChain<I, O>

Source

pub fn new<S: Into<String>>( providers: Vec<(S, SyncProvider<I, O>)>, ) -> Result<Self, &'static str>

Build a new chain from an ordered list of (name, provider) pairs.

Returns Err if providers is empty.

Source

pub fn with_should_fall_back<F>(self, f: F) -> Self
where F: Fn(&DynError) -> bool + Send + Sync + 'static,

Set the predicate that decides whether a given error should cause fallback. Default falls back on any error.

Source

pub fn with_on_fallback<F>(self, f: F) -> Self
where F: Fn(&str, &DynError, &str) + Send + Sync + 'static,

Set the audit callback fired after each fallback. Called with (failed_name, error, next_name) before the next provider is tried.

Source

pub fn with_skip<P>(self, predicate: P) -> Result<Self, &'static str>
where P: Fn(&str) -> bool,

Skip a provider entirely when predicate(&name) returns true. Useful when an upstream circuit breaker says a provider is open. Returns Err if the filter removes every provider.

Source

pub fn names(&self) -> Vec<&str>

Provider names in order.

Source

pub fn call(&self, input: &I) -> Result<ChainResult<O>, DynError>

Try each provider in order until one returns Ok.

Auto Trait Implementations§

§

impl<I, O> Freeze for FallbackChain<I, O>

§

impl<I, O> !RefUnwindSafe for FallbackChain<I, O>

§

impl<I, O> Send for FallbackChain<I, O>

§

impl<I, O> Sync for FallbackChain<I, O>

§

impl<I, O> Unpin for FallbackChain<I, O>

§

impl<I, O> UnsafeUnpin for FallbackChain<I, O>

§

impl<I, O> !UnwindSafe for FallbackChain<I, O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.