fix: normalize multimodal usage details#6248
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughChangesUsage token accounting
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@relay/channel/openai/image_stream_test.go`:
- Around line 39-58: Update
TestNormalizeOpenAIImageUsagePreservesProvidedOutputDetails and
TestNormalizeOpenAIImageUsageCopiesNativeOutputDetails to use testify/assert for
all non-fatal value checks, and add the assert import to the file. Keep the
existing test setup and expectations unchanged.
In `@service/billing_usage_test.go`:
- Around line 7-39: Replace testify/require with testify/assert in
service/billing_usage_test.go lines 7-39 and
service/relayconvert/internal/gemini_chat/to_oai_chat_resp_test.go lines 7-32,
updating every require.Equal and require.Zero assertion in the affected tests to
the corresponding assert method; no other test behavior needs changing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0da8649f-3ce3-48ea-bd01-0a41db157e8a
📒 Files selected for processing (12)
dto/billing_usage.godto/billing_usage_test.godto/openai_response.gorelay/channel/openai/image_stream_test.gorelay/channel/openai/relay_image.goservice/billing_usage.goservice/billing_usage_test.goservice/relayconvert/internal/gemini_chat/to_oai_chat_resp.goservice/relayconvert/internal/gemini_chat/to_oai_chat_resp_test.goservice/relayconvert/internal/oai_chat/to_oai_responses_resp.goservice/relayconvert/internal/oai_responses/to_oai_chat_resp.goservice/relayconvert/internal/oai_responses/to_oai_chat_resp_test.go
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/classic/src/helpers/render.jsx`:
- Around line 1635-1638: The image token handling must preserve legacy usage
logs in both affected sites. In web/classic/src/helpers/render.jsx lines
1635-1638, remove imageInputTokenCount from the destructuring defaults and
compute it afterward using the legacy condition image_input == null &&
image_ratio != null, mapping legacy image_output values to input pricing while
preserving current behavior. In
web/default/src/features/usage-logs/components/dialogs/details-dialog.tsx lines
436-445, apply the same heuristic so legacy image_output values are labeled
“Image input”; no other sites require changes.
In `@web/default/src/i18n/locales/fr.json`:
- Line 2275: Update the French translation for the “Image output” key in fr.json
to the idiomatic “Sortie d’image”, matching the apostrophe style used by the
adjacent translation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 774ba158-8cbf-4a88-8334-ba547efd59fd
📒 Files selected for processing (12)
service/text_quota.goservice/text_quota_test.goweb/classic/src/helpers/render.jsxweb/default/src/features/usage-logs/components/dialogs/details-dialog.tsxweb/default/src/features/usage-logs/types.tsweb/default/src/i18n/locales/en.jsonweb/default/src/i18n/locales/fr.jsonweb/default/src/i18n/locales/ja.jsonweb/default/src/i18n/locales/ru.jsonweb/default/src/i18n/locales/vi.jsonweb/default/src/i18n/locales/zh-TW.jsonweb/default/src/i18n/locales/zh.json
|
|
Tip For best results, initiate chat on the files or code changes.
When you are ready, comment |
|
Tip For best results, initiate chat on the files or code changes.
When ready, use |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
ast-grep outline \
dto/billing_usage_test.go \
relay/channel/openai/image_stream_test.go \
service/billing_usage_test.go \
service/relayconvert/internal/gemini_chat/to_oai_chat_resp_test.go \
service/relayconvert/internal/oai_responses/to_oai_chat_resp_test.go \
--items all
rg -n -C 3 \
'OutputTokensDetails|UsageFromChatUsage|UsageFromResponsesUsage|normalizeOpenAIUsage|UsageFromGeminiMetadata|usageFromGeminiBillingUsage' \
dto relay/channel/openai serviceLength of output: 34558 🏁 Script executed: #!/bin/bash
set -euo pipefail
ast-grep outline service/relayconvert/internal/oai_chat --items all
sed -n '105,165p' service/relayconvert/internal/oai_chat/to_oai_responses_resp.go
fd --type f --extension go . service/relayconvert/internal/oai_chat | sort | while read -r file; do
case "$file" in
*_test.go)
echo "===== $file ====="
ast-grep outline "$file" --items all
;;
esac
doneLength of output: 11171 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '1,155p' service/relayconvert/internal/oai_chat/to_oai_responses_resp_test.goLength of output: 5799 🏁 Script executed: go test ./service/relayconvert/internal/oai_chatLength of output: 3489
This confirms the current baseline is green. The proposed |
Important
📝 变更描述 / Description
完善多模态 usage 明细的归一化与协议透传:Gemini 在 modality 明细不完整时,将 aggregate token 与已知图片、音频和 reasoning 明细之间的正差额归入文本 token,因为发现as资源可能不会直接返回textToken;同时补充 OpenAI
output_tokens_details的数据结构否则会丢失明细、深拷贝及 Responses/Chat 转换支持。这样结算使用的 token 分类与上游 aggregate usage 保持一致,并保留原生输出明细。本提交由 AI 辅助实现和测试;当前 Git 提交者不是该仓库历史核心维护者。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit