Group chat token counts by thousands
This commit is contained in:
@@ -427,9 +427,9 @@ fn generation_summary(stats: crate::app::generation::GenerationStats) -> Element
|
||||
text(format!(
|
||||
"{} · {} input · {} cached · {} output",
|
||||
format_duration(stats.duration_ms as f64 / 1_000.0),
|
||||
stats.input_tokens,
|
||||
stats.cached_tokens,
|
||||
stats.output_tokens,
|
||||
format_token_count(stats.input_tokens),
|
||||
format_token_count(stats.cached_tokens),
|
||||
format_token_count(stats.output_tokens),
|
||||
))
|
||||
.size(11)
|
||||
.color(muted_text()),
|
||||
@@ -441,6 +441,18 @@ fn generation_summary(stats: crate::app::generation::GenerationStats) -> Element
|
||||
.into()
|
||||
}
|
||||
|
||||
fn format_token_count(value: u32) -> String {
|
||||
let digits = value.to_string();
|
||||
let mut output = String::with_capacity(digits.len() + digits.len() / 3);
|
||||
for (index, digit) in digits.chars().enumerate() {
|
||||
if index > 0 && (digits.len() - index).is_multiple_of(3) {
|
||||
output.push(',');
|
||||
}
|
||||
output.push(digit);
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
fn tool_cards(cards: Vec<crate::agent::ToolCard>) -> Element<'static, Message> {
|
||||
let mut rows = column![].spacing(0);
|
||||
for (index, card) in cards.into_iter().enumerate() {
|
||||
@@ -517,3 +529,16 @@ fn tool_cards(cards: Vec<crate::agent::ToolCard>) -> Element<'static, Message> {
|
||||
.style(preference_group_style)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::format_token_count;
|
||||
|
||||
#[test]
|
||||
fn chat_divider_groups_token_counts_by_thousands() {
|
||||
assert_eq!(format_token_count(0), "0");
|
||||
assert_eq!(format_token_count(999), "999");
|
||||
assert_eq!(format_token_count(1_000), "1,000");
|
||||
assert_eq!(format_token_count(12_345_678), "12,345,678");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user