use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextLimit {
pub max_tokens: u64,
pub used_tokens: u64,
pub remaining_tokens: u64,
pub percentage_used: f64,
pub percentage: f64,
}
impl ContextLimit {
pub fn new(used_tokens: u64, max_tokens: u64) -> Self {
let remaining = max_tokens.saturating_sub(used_tokens);
let percentage = if max_tokens > 0 {
(used_tokens as f64 / max_tokens as f64) * 100.0
} else {
0.0
};
Self {
max_tokens,
used_tokens,
remaining_tokens: remaining,
percentage_used: percentage,
percentage,
}
}
pub fn percentage(&self) -> f64 {
self.percentage_used
}
}