-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(spinner): display token usage and cost information during execution #2204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ner to show formatted usage information
refactor(spinner): eliminate Stopwatch and related functionality
| (Some(acc), None) | (None, Some(acc)) => [ | ||
| acc.cost.map(|c| format!("${:.3}", c)), | ||
| Some(format!("{}/{}", *acc.prompt_tokens, *acc.completion_tokens)), | ||
| acc.cache_hit_rate().map(|p| format!("{:.2}%", p)), | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic bug in pattern matching. When accumulated is None and last_request is Some, the pattern (None, Some(acc)) binds acc to last_request, not accumulated. This contradicts the comment on line 2627 which states "Use accumulated for cost and cache rate". In this case, cost and cache_hit_rate will be calculated from last_request instead of accumulated.
The second match arm should only handle (Some(acc), None) to use accumulated data. The (None, Some(last)) case should be handled separately:
(Some(acc), None) => [
acc.cost.map(|c| format!("${:.3}", c)),
Some(format!("{}/{}", *acc.prompt_tokens, *acc.completion_tokens)),
acc.cache_hit_rate().map(|p| format!("{:.2}%", p)),
],
(None, Some(last)) => [
None, // No accumulated cost
Some(format!("{}/{}", *last.prompt_tokens, *last.completion_tokens)),
None, // No accumulated cache rate
],| (Some(acc), None) | (None, Some(acc)) => [ | |
| acc.cost.map(|c| format!("${:.3}", c)), | |
| Some(format!("{}/{}", *acc.prompt_tokens, *acc.completion_tokens)), | |
| acc.cache_hit_rate().map(|p| format!("{:.2}%", p)), | |
| ], | |
| (Some(acc), None) => [ | |
| acc.cost.map(|c| format!("${:.3}", c)), | |
| Some(format!("{}/{}", *acc.prompt_tokens, *acc.completion_tokens)), | |
| acc.cache_hit_rate().map(|p| format!("{:.2}%", p)), | |
| ], | |
| (None, Some(last)) => [ | |
| None, // No accumulated cost | |
| Some(format!("{}/{}", *last.prompt_tokens, *last.completion_tokens)), | |
| None, // No accumulated cache rate | |
| ], |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
| pub fn set_message(&mut self, message: &str) -> Result<()> { | ||
| if let Some(pb) = &self.progress_bar { | ||
| let idx = *self | ||
| .word_index | ||
| .get_or_insert_with(|| rand::rng().random_range(0..THINKING_WORDS.len())); | ||
| let word = THINKING_WORDS[idx].to_string(); | ||
| self.current_message = Some(format!("{} {}", word, message)); | ||
| pb.set_message(message.green().bold().to_string()); | ||
| } | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency between current_message and the displayed message. Line 165 stores the full message including the word prefix (format!("{} {}", word, message)), but line 166 only displays the message parameter without the word prefix. This creates a mismatch between the internal state and what's displayed.
The displayed message should match the stored state:
pub fn set_message(&mut self, message: &str) -> Result<()> {
if let Some(pb) = &self.progress_bar {
let idx = *self
.word_index
.get_or_insert_with(|| rand::rng().random_range(0..THINKING_WORDS.len()));
let word = THINKING_WORDS[idx].to_string();
let full_message = format!("{} {}", word, message);
self.current_message = Some(full_message.clone());
pb.set_message(full_message.green().bold().to_string());
}
Ok(())
}| pub fn set_message(&mut self, message: &str) -> Result<()> { | |
| if let Some(pb) = &self.progress_bar { | |
| let idx = *self | |
| .word_index | |
| .get_or_insert_with(|| rand::rng().random_range(0..THINKING_WORDS.len())); | |
| let word = THINKING_WORDS[idx].to_string(); | |
| self.current_message = Some(format!("{} {}", word, message)); | |
| pb.set_message(message.green().bold().to_string()); | |
| } | |
| Ok(()) | |
| } | |
| pub fn set_message(&mut self, message: &str) -> Result<()> { | |
| if let Some(pb) = &self.progress_bar { | |
| let idx = *self | |
| .word_index | |
| .get_or_insert_with(|| rand::rng().random_range(0..THINKING_WORDS.len())); | |
| let word = THINKING_WORDS[idx].to_string(); | |
| let full_message = format!("{} {}", word, message); | |
| self.current_message = Some(full_message.clone()); | |
| pb.set_message(full_message.green().bold().to_string()); | |
| } | |
| Ok(()) | |
| } | |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
|
Action required: PR inactive for 5 days. |
fixes: #1789