fix(stats): TPM now only counts output tokens#7827
Merged
Conversation
- Add range_total_output_tokens accumulation, separate from total tokens - Change range_avg_tpm formula to use output tokens only - Update i18n labels to reflect Output TPM
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider guarding
range_total_output_tokens += record.token_outputagainstrecord.token_outputbeingNoneor missing to avoid potential runtime errors when older or malformed records are processed. - Now that
range_avg_tpmis output-only, it might be helpful to renamerange_total_tokensto something likerange_total_io_tokens(or similar) where it is still used, to avoid confusion between total tokens and output-only tokens in future maintenance.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider guarding `range_total_output_tokens += record.token_output` against `record.token_output` being `None` or missing to avoid potential runtime errors when older or malformed records are processed.
- Now that `range_avg_tpm` is output-only, it might be helpful to rename `range_total_tokens` to something like `range_total_io_tokens` (or similar) where it is still used, to avoid confusion between total tokens and output-only tokens in future maintenance.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the statistics dashboard to calculate the Average TPM (Tokens Per Minute) based on output tokens instead of total tokens, with corresponding updates to the English, Russian, and Chinese localization files. A review comment points out a potential logic error in the TPM calculation: the total output tokens are accumulated for all records, whereas the total duration used as the denominator only accounts for records with valid start and end times, which could lead to inaccurate averages.
|
Related Documentation 1 document(s) may need updating based on files changed in this PR: AstrBotTeam's Space pr4697的改动View Suggested Changes@@ -904,7 +904,7 @@
- `range_total_calls`:选定时间范围内的总 API 调用次数
- `range_avg_ttft_ms`:首个令牌平均响应时间(毫秒)
- `range_avg_duration_ms`:请求平均持续时间(毫秒)
- - `range_avg_tpm`:平均每分钟令牌数(TPM)
+ - `range_avg_tpm`:平均每分钟输出令牌数(Output TPM),仅统计输出令牌,不包含输入令牌
- `range_success_rate`:API 调用成功率(0-1 之间)
- `range_by_provider`:按提供商分类的令牌消耗排名
- `range_by_umo`:按统一消息来源(UMO)分类的令牌消耗排名 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改动内容
问题
TPM(平均每分钟词元数)之前统计的是总 token(input + output),但作为生成性能指标,应该只统计 output tokens。
改动
stat.py): 新增range_total_output_tokens,仅累加record.token_output,TPM 公式改为使用 output tokens影响
Summary by Sourcery
Update token statistics so that TPM is calculated using only output tokens and align UI labels accordingly.
Bug Fixes:
Enhancements:
Documentation: