pub struct TokenBudget {
pub total: usize,
pub reserve_for_response: usize,
pub floor_per_priority: HashMap<Priority, usize>,
}Expand description
Token budget for one Brief.
total is the inclusive ceiling for the assembled brief; the builder
reserves reserve_for_response tokens for the model’s reply and prunes
contributions until the visible total fits within
total - reserve_for_response. floor_per_priority lets callers
guarantee a minimum allocation per Priority so a flood of
Priority::Low contributions can’t squeeze out Priority::Critical
content.
Fields§
§total: usizeInclusive ceiling for prompt + reserved response, in tokens.
reserve_for_response: usizeTokens held back from the prompt so the model has room to reply.
floor_per_priority: HashMap<Priority, usize>Minimum tokens guaranteed per priority bucket (best-effort: a higher priority can still borrow from a lower floor when over budget).
Implementations§
Source§impl TokenBudget
impl TokenBudget
Sourcepub fn new(total: usize, reserve_for_response: usize) -> Self
pub fn new(total: usize, reserve_for_response: usize) -> Self
Build a budget with total tokens, reserve_for_response held back,
and no per-priority floors. Floors can be added with
TokenBudget::with_floor.
Sourcepub fn with_floor(self, priority: Priority, floor: usize) -> Self
pub fn with_floor(self, priority: Priority, floor: usize) -> Self
Set the minimum tokens guaranteed for priority. Returns self for
chaining.
Sourcepub fn prompt_budget(&self) -> usize
pub fn prompt_budget(&self) -> usize
Tokens available to the prompt (i.e. total - reserve_for_response),
saturating at zero if the reserve exceeds the total.
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 moreSource§impl Debug for TokenBudget
impl Debug for TokenBudget
Source§impl Default for TokenBudget
impl Default for TokenBudget
Source§impl<'de> Deserialize<'de> for TokenBudget
impl<'de> Deserialize<'de> for TokenBudget
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for TokenBudget
impl PartialEq for TokenBudget
Source§fn eq(&self, other: &TokenBudget) -> bool
fn eq(&self, other: &TokenBudget) -> bool
self and other values to be equal, and is used by ==.