fix: responses cache token 未计费 - #1509
Conversation
WalkthroughThe changes add nil checks to safely handle usage details in AI response handlers. The frontend's Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (3)
relay/channel/openai/relay_responses.go (1)
57-97: Cached token details are not propagated in the streaming-case handler
OaiResponsesStreamHandlermirrors the non-stream path but never forwardsCachedTokens.
For consistency (and to avoid confusing front-end numbers) please aggregate the cached tokens in the"response.completed"branch in the same way you did above.
Failing to do so will showcache_ratioin the UI whilecache_tokensremain zero.web/src/helpers/render.js (1)
1153-1161: Signature change is breaking for every call-site that still uses the old positional order
renderLogContentnow insertscacheRatiobeforeimage, shifting all following
positional parameters. Any caller that was not updated will silently mis-map
arguments (a boolean will be read as the ratio, etc.).Add backward-compatibility logic or migrate all callers in a single commit.
export function renderLogContent( modelRatio, completionRatio, modelPrice = -1, groupRatio, user_group_ratio, - cacheRatio = 1.0, - image = false, + // Accept both old and new call-sites + cacheRatioOrImage = 1.0, + image = false, imageRatio = 1.0, @@ ) { - const { ratio, label: ratioLabel, useUserGroupRatio: useUserGroupRatio } = getEffectiveRatio(groupRatio, user_group_ratio); + // Old signature passed a boolean here; detect & adapt + let cacheRatio = cacheRatioOrImage; + if (typeof cacheRatioOrImage === 'boolean') { + image = cacheRatioOrImage; + cacheRatio = 1.0; + } + const { ratio, label: ratioLabel, useUserGroupRatio } = + getEffectiveRatio(groupRatio, user_group_ratio);web/src/hooks/usage-logs/useUsageLogsData.js (1)
369-376: Update all renderLogContent calls to include the new cacheRatio parameterWe detected two remaining outdated usages of renderLogContent that still pass the old 11-argument signature. Please update these call sites to pass the new
cacheRatiovalue (e.g. default to1.0or derive from context):• web/src/hooks/usage-logs/useUsageLogsData.js: line 363
• web/src/helpers/render.js: line 1153After making those changes, rerun the repository-wide check to confirm no calls remain with ≤ 11 arguments.
🧹 Nitpick comments (2)
web/src/helpers/render.js (2)
1176-1187: Always printing缓存倍率even when it is 1.0 clutters the logTypical requests will keep
cacheRatioat the default1.0; showing it adds no
value. Consider omitting the fragment when the ratio equals1.
1200-1210: Same duplication issue for the non-image / non-webSearch branchRefactor the string builder so that the
缓存倍率fragment is appended only if
cacheRatio !== 1.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
relay/channel/openai/relay_responses.go(1 hunks)web/src/helpers/render.js(4 hunks)web/src/hooks/usage-logs/useUsageLogsData.js(1 hunks)
…cache-token fix: responses cache token 未计费
Summary by CodeRabbit