fix: 修复智普、Moonshot渠道在stream=true时无法拿到cacheTokens的统计数据。 - #2550
Conversation
根本原因: 1. 在OaiStreamHandler流式处理函数中,调用applyUsagePostProcessing(info, usage, nil)时传入的responseBody为nil,导致无法从响应体中提取缓存tokens。 2. 两个渠道的cached_tokens位置不同: - 智普:标准位置 usage.prompt_tokens_details.cached_tokens - Moonshot:非标准位置 choices[].usage.cached_tokens 处理方案: 1. 传递body信息到applyUsagePostProcessing中 2. 拆分智普和Moonshot的解析,并为Moonshot单独写一个解析方法。
WalkthroughModified OaiStreamHandler to pass last streamed data to applyUsagePostProcessing; refactored ChannelType handling to give Moonshot a dedicated case with custom cached-tokens extraction from non-standard response body structure; added extractMoonshotCachedTokensFromBody helper function with fallback chain. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2025-08-21T06:31:11.073ZApplied to files:
📚 Learning: 2025-06-21T03:37:41.726ZApplied to files:
🔇 Additional comments (4)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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 |
根本原因:
处理方案:
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.