pub struct Fallback<A, B> { /* private fields */ }Expand description
Try primary; on a failure another provider might survive, try secondary.
use io_harness::provider::Fallback;
use io_harness::{Anthropic, OpenRouter};
let provider = Fallback::new(OpenRouter::from_env()?, Anthropic::from_env()?);Implementations§
Trait Implementations§
Source§impl<A: Provider + Sync, B: Provider + Sync> Provider for Fallback<A, B>
impl<A: Provider + Sync, B: Provider + Sync> Provider for Fallback<A, B>
Source§fn accepts_images(&self) -> bool
Available on crate feature media only.
fn accepts_images(&self) -> bool
media only.Both, or neither. Reporting the primary’s answer would let an image reach
a secondary that cannot read it on the one call that matters — the
fallover — and a fallover already means something has gone wrong. The
secondary would refuse it (ensure_media_accepted runs inside every
built-in provider too), so the only thing the conjunction changes is
when the caller finds out: before the run, rather than mid-fallover.
Source§fn endpoint(&self) -> Option<&str>
fn endpoint(&self) -> Option<&str>
The primary’s, for the single-endpoint callers that predate fallback.
endpoints is what authorization uses.
Source§fn endpoints(&self) -> Vec<&str>
fn endpoints(&self) -> Vec<&str>
BOTH providers’ endpoints.
This is the reason endpoints exists at all. The 0.8.0 egress policy is
deny-by-default and a run authorizes its provider’s host before its first
step; a combinator that reported only the primary’s host would leave the
secondary’s completely ungoverned, so a fallback would be a way to reach a
host the policy never saw.
Source§fn last_served(&self) -> Option<String>
fn last_served(&self) -> Option<String>
The LEAF that answered, not the branch it sits in.
A nested Fallback::new(a, Fallback::new(b, c)) whose c answered must
record "c", not "b -> c": the row exists because one label for a whole
run stops being true the moment a run can use two, and naming a sub-chain
reintroduces exactly that ambiguity one level down.
Source§async fn complete(
&self,
request: CompletionRequest,
) -> Result<CompletionResponse>
async fn complete( &self, request: CompletionRequest, ) -> Result<CompletionResponse>
Auto Trait Implementations§
impl<A, B> !Freeze for Fallback<A, B>
impl<A, B> RefUnwindSafe for Fallback<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Fallback<A, B>
impl<A, B> Sync for Fallback<A, B>
impl<A, B> Unpin for Fallback<A, B>
impl<A, B> UnsafeUnpin for Fallback<A, B>where
A: UnsafeUnpin,
B: UnsafeUnpin,
impl<A, B> UnwindSafe for Fallback<A, B>where
A: UnwindSafe,
B: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.