pub struct QuotaGuard { /* private fields */ }Expand description
A provider wrapper for one account. After a failure that no other model of the account can avoid (a used-up quota, an account that cannot pay, a rejected credential) it answers every call with that error, without sending it, until the cooldown ends: until the quota’s stated reset, or for a fixed time when there is none.
Wrap each configured account once and share the guard (it is cheap to
clone through an Arc): every caller then learns from the first
failure, and a crate::Failover chain moves past the account’s other
models at once instead of retrying each.
Implementations§
Source§impl QuotaGuard
impl QuotaGuard
Trait Implementations§
Source§impl Provider for QuotaGuard
impl Provider for QuotaGuard
fn name(&self) -> &str
Source§fn default_model(&self) -> Option<&str>
fn default_model(&self) -> Option<&str>
The model to use when the agent names none.
None (the default)
means the agent must name one with crate::AgentBuilder::model;
a provider that serves one model, or a test double, says which.fn complete<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ModelRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelResponse, ProviderError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuotaGuard: 'async_trait,
When
model can next be asked, if this provider already knows it
cannot answer now (a used-up quota, a rejected credential, no
credit; see crate::QuotaGuard). None: it may answer now.fn stream<'a>( &'a self, request: &'a ModelRequest, ) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, ProviderError>> + Send + 'a>>
Auto Trait Implementations§
impl !Freeze for QuotaGuard
impl !RefUnwindSafe for QuotaGuard
impl !UnwindSafe for QuotaGuard
impl Forget for QuotaGuard
impl Move for QuotaGuard
impl Send for QuotaGuard
impl Sync for QuotaGuard
impl Unpin for QuotaGuard
impl UnsafeUnpin for QuotaGuardwhere
*const ArcInner<dyn Provider> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Provider>>: UnsafeUnpin,
Align4<u32>: UnsafeUnpin,
Align1<u8>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<(Option<String>, Cooldown)>: UnsafeUnpin,
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
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> ⓘ
Converts
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> ⓘ
Converts
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 more