feat: usage logs add completion ratio#3435
feat: usage logs add completion ratio#3435feitianbubu wants to merge 1 commit intoQuantumNous:mainfrom
Conversation
WalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/src/helpers/render.jsx`:
- Around line 1363-1372: Guard the completion price by converting
completionRatio to a numeric value and only render when it's a finite number (so
numeric zero is allowed); specifically, in render.jsx compute a numeric ratio
from completionRatio (e.g., via Number(...) or Number.isFinite check) and
replace the current truthiness check with a check like Number.isFinite(ratio)
before pushing the segment that calls formatCompactDisplayPrice with modelRatio
* 2.0 * ratio, ensuring you use the validated numeric variable rather than
coercing inside the formatting call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9a9115cc-219c-47cc-9988-eb3ed46f616e
📒 Files selected for processing (2)
web/src/components/table/usage-logs/UsageLogsColumnDefs.jsxweb/src/helpers/render.jsx
| if (completionRatio) { | ||
| segments.push({ | ||
| tone: 'secondary', | ||
| text: i18next.t('补全 {{price}} / 1M tokens', { | ||
| price: formatCompactDisplayPrice( | ||
| modelRatio * 2.0 * Number(completionRatio), | ||
| ), | ||
| }), | ||
| }); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify completion_ratio production/consumption and finite-value guards.
echo "== completion_ratio producers/consumers =="
rg -n -C3 '\bcompletion_ratio\b|\bcompletionRatio\b'
echo
echo "== inspect ratio sync guard implementation (if present) =="
fd ratio_sync.go --exec sed -n '560,700p' {}Repository: QuantumNous/new-api
Length of output: 50376
🏁 Script executed:
sed -n '1298,1380p' web/src/helpers/render.jsx | cat -nRepository: QuantumNous/new-api
Length of output: 3073
🏁 Script executed:
rg -n 'renderPriceSimpleCore\(' web/src/ -A2 | head -50Repository: QuantumNous/new-api
Length of output: 393
🏁 Script executed:
rg -n 'formatCompactDisplayPrice' web/src/helpers/render.jsx -A5 | head -40Repository: QuantumNous/new-api
Length of output: 1262
Guard completionRatio before rendering completion price.
Line 1363 uses truthiness and line 1368 coerces with Number(...), which can render invalid prices when completionRatio is undefined, null, zero, or malformed (¥NaN, ¥Infinity, or inconsistent hiding of numeric zero).
💡 Suggested fix
- if (completionRatio) {
+ const completionRatioValue = Number(completionRatio);
+ const hasCompletionRatio =
+ completionRatio !== undefined &&
+ completionRatio !== null &&
+ Number.isFinite(completionRatioValue) &&
+ completionRatioValue >= 0;
+ if (hasCompletionRatio) {
segments.push({
tone: 'secondary',
text: i18next.t('补全 {{price}} / 1M tokens', {
price: formatCompactDisplayPrice(
- modelRatio * 2.0 * Number(completionRatio),
+ modelRatio * 2.0 * completionRatioValue,
),
}),
});
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (completionRatio) { | |
| segments.push({ | |
| tone: 'secondary', | |
| text: i18next.t('补全 {{price}} / 1M tokens', { | |
| price: formatCompactDisplayPrice( | |
| modelRatio * 2.0 * Number(completionRatio), | |
| ), | |
| }), | |
| }); | |
| } | |
| const completionRatioValue = Number(completionRatio); | |
| const hasCompletionRatio = | |
| completionRatio !== undefined && | |
| completionRatio !== null && | |
| Number.isFinite(completionRatioValue) && | |
| completionRatioValue >= 0; | |
| if (hasCompletionRatio) { | |
| segments.push({ | |
| tone: 'secondary', | |
| text: i18next.t('补全 {{price}} / 1M tokens', { | |
| price: formatCompactDisplayPrice( | |
| modelRatio * 2.0 * completionRatioValue, | |
| ), | |
| }), | |
| }); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@web/src/helpers/render.jsx` around lines 1363 - 1372, Guard the completion
price by converting completionRatio to a numeric value and only render when it's
a finite number (so numeric zero is allowed); specifically, in render.jsx
compute a numeric ratio from completionRatio (e.g., via Number(...) or
Number.isFinite check) and replace the current truthiness check with a check
like Number.isFinite(ratio) before pushing the segment that calls
formatCompactDisplayPrice with modelRatio * 2.0 * ratio, ensuring you use the
validated numeric variable rather than coercing inside the formatting call.
使用日志, 详情增加补全价格显示

Summary by CodeRabbit