-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: add model usage statistics with input/output token breakdown to stats command #6296
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: dev
Are you sure you want to change the base?
Conversation
|
/review |
| console.log("┌────────────────────────────────────────────────────────┐") | ||
| console.log("│ MODEL USAGE │") | ||
| console.log("├────────────────────────────────────────────────────────┤") | ||
|
|
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.
Suggestion: Long model names (e.g., openrouter/anthropic/claude-3.5-sonnet:beta) could exceed 54 characters and break the table layout. Consider truncating similar to how tool names are handled in the TOOL USAGE section below (see lines 287-289).
| let sessionCost = 0 | ||
| let sessionTokens = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } } | ||
| let sessionToolUsage: Record<string, number> = {} | ||
| let sessionModelUsage: Record< |
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.
Minor suggestion: This type definition duplicates the one in SessionStats.modelUsage. You could extract a named type like type ModelUsageStats = { messages: number; tokens: { input: number; output: number }; cost: number } and reuse it. This is optional - the current approach works fine too.
|
should prolly require a flag to output this btw, and maybe a flag to limit # of models cause mine is huge |
that sounds fair! yeah sure, perhaps just to follow the convention about days followed by the number of models we want to display? and if so, what sorting would we need? top Y in terms of usage? |
c696f3a to
ec61409
Compare
|
@rekram1-node I pushed a change, so it is a flag now, with the option to also limit the amount of models sorted by top messages |
6602d9b to
a88e7ce
Compare
|
/review |
| let modelLimit: number | undefined | ||
| if (args.models === true) { | ||
| modelLimit = Infinity | ||
| } else if (typeof args.models === "number") { |
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.
Style guide suggests avoiding let statements. Consider using an IIFE or ternary to avoid the let:
| } else if (typeof args.models === "number") { | |
| const modelLimit = (() => { | |
| if (args.models === true) return Infinity | |
| if (typeof args.models === "number") return args.models | |
| return undefined | |
| })() |
This is just a suggestion - the current code is perfectly readable and functional.
Summary
This PR enhances the
statscommand to provide granular visibility into model usage. It introduces a new "MODEL USAGE" section that displays message counts, a breakdown of input vs. output tokens, and historical accumulated costs for each model used across sessions.Changes
SessionStatsto include amodelUsagerecord.aggregateSessionStatsto collect and sum usage metrics (messages, tokens, cost) per provider/model from assistant messages.--models X, when given will show the models and the top X, if X is not given will show them all, sorted by total messagesdisplayStatsto render a sorted table of model usage, showing:Example Output