Repository navigation
Conversation
Use valid unfiltered Imagen payloads and the larger Jimeng URL/base64 count to update the existing fixed-price and expression quantities. Keep the reserved quantity when the response count is zero or invalid.
|
| Layer / File(s) | Summary |
|---|---|
Gemini prediction billing count relay/channel/gemini/relay-gemini.go, relay/channel/gemini/relay_gemini_usage_test.go |
Gemini counts unfiltered predictions with nonblank base64 data for billing while retaining all unfiltered predictions in the response. Tests check billing counts, response entries, and error cases. |
Jimeng payload billing count relay/channel/jimeng/image.go, relay/channel/jimeng/image_test.go |
Jimeng counts nonblank URLs and base64 payloads separately, then records the larger count. JSON handling uses common.Unmarshal and common.Marshal. Tests cover payload counts and billing outcomes. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Priority:
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
#8013: The PR counts valid returned Imagen base64 payloads and passes that count toUpdateImageCount, addressing the reported billing mismatch.#8014: The PR counts valid Jimeng URL and base64 payloads, avoids double-counting, and passes the result toUpdateImageCount.
Suggested reviewers: feitianbubu
Merge Risk: 
Minimal · up to ecc66
-
The image billing changes are ready to merge after normal checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
PR satisfies the coding requirements for
#8013and#8014.GeminiImageHandlercounts nonblank, non-filtered base64 payloads and callsUpdateImageCount.jimengImageHandlercounts nonblank URL and base64 entries and uses the larger count.UpdateImageCountpreserves the reserved quantity for zero or out-of-range counts and updates fixed-price and expression billing. The regression tests cover filtering, blank payloads, differing counts, duplicate representations, expression billing, boundary counts, and errors. The current-head changes add comments only and do not alter this implementation.
-
Full details: Out of Scope Changes check
-
Explanation
relay/channel/jimeng/image.gochanges JSON parsing and serialization fromencoding/jsontocommon.Unmarshalandcommon.Marshal. Issues#8013and#8014require payload-based billing count updates. They do not require a JSON wrapper change, and the current wrapper still uses the standard-library codec. The change therefore adds no demonstrated behavior for either issue and is outside the linked scope.Resolution
Remove the
common.Unmarshalandcommon.Marshalreplacement. Keep the existingencoding/jsoncalls and retain the payload counting,UpdateImageCountcall, and regression tests.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit counts each image bright,
Base64 and URLs in sight.
Blank payloads leave the bill,
Filtered predictions count not still.
Tests check each number right,
Then hop away beneath moonlight.
Comment @coderabbitai help to get the list of available commands.
|
@coderabbitai 已在 fa90a4f 补充两个图片 handler、转换函数和回归用例的说明,本次仅修改注释。 关于 JSON 入口: 复核: |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain
JSON 入口的说明正确,也与已有项目规范 Learning 一致:
你报告的串行 race 测试、 🧠 Learnings used
You are interacting with an AI system. |
|
@coderabbitai 此前的复核回复已确认统一 JSON 入口符合 摘要中的 |
🧩 Analysis chain
本次核对也与已有 JSON 规范 Learning 一致,无需新增规则。 我将触发摘要重新生成,并要求将 🧠 Learnings used
✅ Action performed
|
Agent
本 PR 由 Codex 辅助编写。
Links
Kind
Issue facts
Change
Imagen 计数未过滤且非空的 base64;即梦取有效 URL 数与 base64 数的较大值,避免同图两种表示重复计数。两者调用现有
UpdateImageCount,更新固定价 n 与表达式数量;零或超限结果保留预留值。即梦 JSON 调用改用项目统一入口
common.Marshal/Unmarshal;当前 codec 仍调用标准库encoding/json,没有切换 JSON 引擎。Research
两条响应路径补齐同一计费事实缺口。
Duplicate / prior art
Imagen count、即梦 张数、Jimeng billing、UpdateImageCount、图片 张数。Docs and code
.agents/rules/billing.md的响应图片计数规则。relay/image_handler.go预留后调用适配器,再交给PostTextConsumeQuota;两个 handler 需在其间更新实际数量。Alternatives considered
Files
relay/channel/gemini/relay-gemini.gorelay/channel/gemini/relay_gemini_usage_test.gorelay/channel/jimeng/image.gorelay/channel/jimeng/image_test.goBehavior
Verification
go test ./relay/channel/gemini ./relay/channel/jimeng -count=1 -run 'Test(Gemini|Jimeng)ImageHandlerBillsPayloadCount':仅加测试时两包失败,观测 expected 2/actual 4、expected 1/actual 4 和实际数量 nil;补齐调用后两包通过。go test ./relay/channel/gemini ./relay/channel/jimeng -count=1:两包通过。go test -race -parallel=1 ./relay/channel/gemini ./relay/channel/jimeng -count=1:两包通过,含 18 个新子用例。go vet ./relay/channel/gemini ./relay/channel/jimeng && go build ./...:退出码 0。-race因既有gin.SetMode竞争失败,原 main 生产代码与测试经 overlay 同样失败;串行 race 通过。真实厂商可用性、钱包余额和日志未实跑,issue 金额为合成单价公式推导。既有竞争涉及
TestGeminiChatHandlerCompletionTokensExcludeToolUsePromptTokens、TestGeminiTextGenerationHandlerUsesEstimatedPromptTokensWhenUsagePromptMissing、TestGeminiChatHandlerPromptOnlyUsageMetadataEstimatesCompletionTokens、TestGeminiChatHandlerMissingUsageMetadataBuildsEstimatedBillingUsage、TestGeminiTextGenerationHandlerPromptTokensIncludeToolUsePromptTokens、TestGeminiChatHandlerUsesEstimatedPromptTokensWhenUsagePromptMissing;baseline 运行还报告TestStreamResponseGeminiChat2OpenAIAttachesUsageMetadata。本次复核(
fa90a4f8f,仅函数注释):go test -race -parallel=1 ./relay/channel/gemini ./relay/channel/jimeng -count=1→ 两包通过(2.463s / 2.735s);gofmt、git diff --check通过。最新补充(
ecc66ddee):完善相邻转换函数与既有 usage 元数据回归的说明,仅修改注释;gofmt、git diff --check通过。CI:最新运行记录,后端 vet/build/test、前端 typecheck/test 均通过(提交
ecc66ddee)。Risks
Summary by CodeRabbit