feat(usage): 新增汇总「总计」行 + -v 多 vendor / --model 多 model_served 过滤支持#135
Merged
Conversation
- stats.py: show_usage 在表格末尾追加「总计」行,汇总请求数、各类 Token、Cost(支持多币种拼接)及加权平均耗时 - db.py: query_usage 的 vendor 参数扩展为 str | list[str] | None,SQL 改用 IN (?, ...) 子句安全过滤多 vendor - cli/__init__.py: usage 命令解析逗号分隔 vendor(如 -v anthropic,zhipu),单 vendor 保持 str 类型向后兼容 - tests: 新增 TestMultiVendorFilter 测试类,覆盖多 vendor 解析、空格去除、与时间维度组合等场景 🤖 Generated with [Claude Code](https://github.com/claude) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
- db.py: query_usage 的 model 参数类型扩展为 str | list[str] | None,过滤字段从 model_requested 改为 model_served,SQL 改用 IN (?, ...) 子句 - stats.py: show_usage 的 model 参数签名同步扩展为 str | list[str] | None - cli/__init__.py: usage 命令解析逗号分隔 model(如 --model glm-5,glm-5.1),更新 help 文本说明过滤 model_served,_run_usage 签名扩展 - tests: 新增 TestMultiModelFilter 测试类(6 个用例),更新 test_query_daily_model_filter_still_works 测试数据与注释以对齐新语义 🤖 Generated with [Claude Code](https://github.com/claude) Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
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.
变更概述
为
coding-proxy usage指令增强查询能力,包含三项功能改进:1. 新增汇总「总计」行
在 usage 统计表格末尾追加加粗的「总计」行,汇总当前查询范围内的:
$X.XX + ¥Y.YY)Σ(avg_ms × requests) / Σrequests),比行级简单平均更准确支持所有时间维度查询:
-d(按日)、-w(按周)、-m(按月)、-t(全量)。2.
-v多 vendor 过滤支持逗号分隔指定多个供应商,如
-v anthropic,zhipu。str类型(向后兼容)AND vendor IN (?, ?)子句,安全无 SQL 注入风险3.
--model改为按model_served过滤 + 支持多值model_requested改为model_served,按实际服务模型查用量,语义更清晰--model glm-5,glm-5.1-v完全对称涉及文件
src/coding/proxy/logging/db.pyquery_usage的vendor/model参数类型扩展为str | list[str] | None,model过滤字段改为model_served,SQL 使用IN (...)src/coding/proxy/logging/stats.pyshow_usage增加汇总累计变量 + 总计行渲染;vendor/model参数签名同步扩展src/coding/proxy/cli/__init__.pyusage()解析逗号分隔 vendor/model;--modelhelp 文本更新;_run_usage签名扩展tests/test_cli_usage.pyTestMultiVendorFilter(6 用例)+TestMultiModelFilter(6 用例)tests/test_token_logger.pytest_query_daily_model_filter_still_works测试数据以对齐model_served新语义测试验证
全量 1061 个测试通过,0 失败。
🤖 Generated with Claude Code