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
impl Copy for UsageTotals
Source§impl Debug for UsageTotals
impl Debug for UsageTotals
Source§impl Default for UsageTotals
impl Default for UsageTotals
Source§impl<'de> Deserialize<'de> for UsageTotals
impl<'de> Deserialize<'de> for UsageTotals
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 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.
Source§impl PartialEq for UsageTotals
impl PartialEq for UsageTotals
Source§impl Serialize for UsageTotals
impl Serialize for UsageTotals
impl StructuralPartialEq for UsageTotals
Auto Trait Implementations§
impl Freeze for UsageTotals
impl RefUnwindSafe for UsageTotals
impl Send for UsageTotals
impl Sync for UsageTotals
impl Unpin for UsageTotals
impl UnsafeUnpin for UsageTotals
impl UnwindSafe for UsageTotals
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> IntoToolOutput for Twhere
T: Serialize + 'static,
impl<T> IntoToolOutput for Twhere
T: Serialize + 'static,
Source§fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>
fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>
Source§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<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.