feat(adapters): Anthropic+Gemini ResponseParser 补读 cachedTokens - #2568
feat(adapters): Anthropic+Gemini ResponseParser 补读 cachedTokens#2568littlebird69 wants to merge 2 commits into
Conversation
|
This PR has conflicts with the git fetch origin
git checkout feat/cache-pricing
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved. Automated notification by github-manager-bot |
Anthropic 非流式 parseMessage: message.usage().cacheReadInputTokens() 返回 Optional<Long>,orElse(0L).intValue() 强转(Gemini 侧是 Optional<Integer> 不需强转,两侧写法不同)。Gemini parseResponse: metadata.cachedContentTokenCount()。DashScope/Ollama 不改(供应商 DTO 无 cached 字段)。流式 parseStreamEvents 不改(Anthropic MessageDelta.usage() 只有 outputTokens,无缓存字段)。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
5cfa93a to
b4bb649
Compare
|
👍 轻提醒一下这个 PR。 它让 Anthropic 和 Gemini 的 ResponseParser 读取供应商响应里已有的 cachedTokens—— 改动很小(每个 parser 各加一行 + 对应测试),已 rebase 到最新 main、无冲突,既有测试全过。两个 SDK 返回类型不同( 麻烦有空时帮忙看看,谢谢!如果有需要先开 Issue 或调整写法的地方,也请告知。 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Reviewed the changes in this PR. The modifications look reasonable and follow the project conventions.
Automated review by "github-manager-bot"
问题
ChatUsage有cachedTokens字段,但 Anthropic 和 Gemini 的 ResponseParser 从没填过它——恒为 0。两个供应商其实在响应里都返回了缓存命中 token 数:
Usage.cacheReadInputTokens()(字段cache_read_input_tokens)GenerateContentResponseUsageMetadata.cachedContentTokenCount()下游依赖
getCachedTokens()的代码(如按缓存命中拆算金额的用量账本)即使在缓存命中时也拿到 0。改动
AnthropicResponseParser.parseMessage:补读cacheReadInputTokens()(非流式)GeminiResponseParser.parseResponse:补读cachedContentTokenCount()MessageDeltaUsage也暴露了cacheReadInputTokens(),可作为后续增强)测试
两个 parser 各加一条测试,断言
getCachedTokens()等于构造响应里的缓存值。既有测试全过。