pub struct Usage {
pub input: InputTokens,
pub output: OutputTokens,
pub raw: Option<JsonObject>,
}Expand description
Token usage of a single language model call or of several added calls.
Every counter is optional because providers report different subsets.
Standard fields that cannot be mapped are None; the provider’s original
usage object is available in raw.
Fields§
§input: InputTokensInput (prompt) token counts.
output: OutputTokensOutput (completion) token counts.
raw: Option<JsonObject>Provider-specific usage object as returned by the API.
Implementations§
Source§impl Usage
impl Usage
Sourcepub fn totals(input: u64, output: u64) -> Self
pub fn totals(input: u64, output: u64) -> Self
Creates a usage with only the total input and output counts set.
Sourcepub fn add(&self, other: &Usage) -> Usage
pub fn add(&self, other: &Usage) -> Usage
Adds two usages counter by counter.
None + None = None; Some(a) + None = Some(a). The raw object is
dropped because provider payloads cannot be combined generically.
Sourcepub fn total_tokens(&self) -> Option<u64>
pub fn total_tokens(&self) -> Option<u64>
Total tokens: input total plus output total (None when both unknown).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Usage
impl<'de> Deserialize<'de> for Usage
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Usage
impl StructuralPartialEq for Usage
Auto Trait Implementations§
impl Freeze for Usage
impl RefUnwindSafe for Usage
impl Send for Usage
impl Sync for Usage
impl Unpin for Usage
impl UnsafeUnpin for Usage
impl UnwindSafe for Usage
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.