pub struct TokenBudget { /* private fields */ }Expand description
Cumulative token budget with threshold callbacks.
Cloning shares one running total, so a single budget can span several
Sessions. See the module docs for what
a budget can and cannot see.
Implementations§
Source§impl TokenBudget
impl TokenBudget
Sourcepub fn builder() -> TokenBudgetBuilder
pub fn builder() -> TokenBudgetBuilder
Start building a budget.
Sourcepub fn record(&self, tokens: Option<u64>)
pub fn record(&self, tokens: Option<u64>)
Add a turn’s token usage to the running total.
None records a turn the CLI reported no usage for. It does not move
the total, and is counted by
turns_missing_usage so the gap stays
visible rather than reading as zero consumption.
Fires on_warning the first time the total reaches warn_at_tokens,
and on_exceeded the first time it reaches max_tokens.
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Err(Error::TokenBudgetExceeded) once the total reaches max_tokens.
Ok(()) when no ceiling is set.
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
Tokens recorded so far.
Sourcepub fn turns_missing_usage(&self) -> usize
pub fn turns_missing_usage(&self) -> usize
Turns recorded with no usage reported.
These consumed tokens the total does not include, so a non-zero count means the total is a floor rather than a measure.
Sourcepub fn remaining_tokens(&self) -> Option<u64>
pub fn remaining_tokens(&self) -> Option<u64>
Tokens left before the ceiling, or None when there is no ceiling.
Saturates at zero rather than going negative: a turn can overshoot, since usage is only known once it has been spent.
Sourcepub fn max_tokens(&self) -> Option<u64>
pub fn max_tokens(&self) -> Option<u64>
The configured ceiling, if any.
Sourcepub fn warn_at_tokens(&self) -> Option<u64>
pub fn warn_at_tokens(&self) -> Option<u64>
The configured warning threshold, if any.
Trait Implementations§
Source§impl Clone for TokenBudget
impl Clone for TokenBudget
Source§fn clone(&self) -> TokenBudget
fn clone(&self) -> TokenBudget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more