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>
impl<I, O> FallbackChain<I, O>
Sourcepub fn new<S: Into<String>>(
providers: Vec<(S, SyncProvider<I, O>)>,
) -> Result<Self, &'static str>
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.
Sourcepub fn with_should_fall_back<F>(self, f: F) -> Self
pub fn with_should_fall_back<F>(self, f: F) -> Self
Set the predicate that decides whether a given error should cause fallback. Default falls back on any error.
Sourcepub fn with_on_fallback<F>(self, f: F) -> Self
pub fn with_on_fallback<F>(self, f: F) -> Self
Set the audit callback fired after each fallback. Called with
(failed_name, error, next_name) before the next provider is tried.
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> 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