use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::totals::TokenTotals;
#[derive(Debug, Clone, Default)]
pub struct GlobalTokenSnapshot {
pub input: u64,
pub output: u64,
pub total: TokenTotals,
pub totals: TokenTotals,
pub request_count: u64,
}
impl GlobalTokenSnapshot {
pub fn new(input: u64, output: u64, _total: u64) -> Self {
Self {
input,
output,
total: TokenTotals::new(input, output),
totals: TokenTotals::new(input, output),
request_count: 0,
}
}
pub fn summary(&self) -> String {
format!(
"{} total tokens ({} input, {} output)",
self.totals.total(),
self.input,
self.output
)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TokenUsageSnapshot {
pub name: String,
pub prompt_tokens: u64,
pub completion_tokens: u64,
pub total_tokens: u64,
pub totals: TokenTotals,
pub timestamp: DateTime<Utc>,
pub request_count: u64,
}
impl TokenUsageSnapshot {
pub fn current() -> Self {
let (prompt, comp, total) = super::super::TOKEN_USAGE.get();
Self {
name: "global".to_string(),
prompt_tokens: prompt,
completion_tokens: comp,
total_tokens: total,
totals: TokenTotals::new(prompt, comp),
timestamp: Utc::now(),
request_count: 0,
}
}
pub fn summary(&self) -> String {
format!(
"{} total tokens ({} input, {} output)",
self.totals.total(),
self.prompt_tokens,
self.completion_tokens
)
}
}