pub struct UsageTotals {
pub tokens: Usage,
pub cost: f64,
pub unpriced: u64,
pub calls: u64,
}Expand description
Many calls’ Usage summed for a running account: the token counters,
the known cost, and how many calls the sum holds and how many of them
were not fully priced.
use rig_core::completion::{Usage, UsageTotals};
let mut totals = UsageTotals::default();
totals.record(&Usage::new().input_tokens(100).output_tokens(20).total_tokens(120));
assert_eq!((totals.calls, totals.unpriced, totals.uncached_input()), (1, 1, 100));Fields§
§tokens: UsageThe token counters summed, with no cost: a call that did not report a counter adds nothing to it.
cost: f64The known costs summed, in USD.
unpriced: u64The calls whose cost is not known, or known only in part, so
Self::cost is a lower bound when any.
calls: u64The calls summed.
Implementations§
Source§impl UsageTotals
impl UsageTotals
Sourcepub fn add(&mut self, other: &UsageTotals)
pub fn add(&mut self, other: &UsageTotals)
Adds what other summed.
Sourcepub fn uncached_input(&self) -> u64
pub fn uncached_input(&self) -> u64
Input tokens neither read from nor written to a cache.
Sourcepub fn total_tokens(&self) -> u64
pub fn total_tokens(&self) -> u64
The tokens read and written, cached input included.
Sourcepub fn cost_label(&self) -> Option<String>
pub fn cost_label(&self) -> Option<String>
The cost as $0.123, ending in + when some calls were not priced,
or None when no call was.
Sourcepub fn cost_or_tokens(&self) -> String
pub fn cost_or_tokens(&self) -> String
The cost, or as 1.2M tokens when no call was
priced, such as a local or subscription model’s.
Trait Implementations§
Source§impl Clone for UsageTotals
impl Clone for UsageTotals
Source§fn clone(&self) -> UsageTotals
fn clone(&self) -> UsageTotals
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for UsageTotals
Source§impl Debug for UsageTotals
impl Debug for UsageTotals
Source§impl Default for UsageTotals
impl Default for UsageTotals
Source§fn default() -> UsageTotals
fn default() -> UsageTotals
Source§impl<'de> Deserialize<'de> for UsageTotals
impl<'de> Deserialize<'de> for UsageTotals
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<UsageTotals, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<UsageTotals, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for UsageTotals
One line for a person or a log: the calls, the tokens by kind and the
cost.
impl Display for UsageTotals
One line for a person or a log: the calls, the tokens by kind and the cost.