Repository navigation
Conversation
Add support for syncing cache creation ratios from OpenRouter and models.dev: - Add "create_cache_ratio" to ratioTypes list in controller - Parse InputCacheWrite from OpenRouter pricing data and convert to create_cache_ratio - Add CacheWrite field to models.dev cost/candidate structs - Prefer candidates with richer cache metadata in models.dev selection - Add createCacheRatioMap for both upstream sources - Update frontend to handle CreateCacheRatio in sync operations - Add "缓存创建倍率" (Cache Create Ratio) option in UI This enables proper pricing for cache write operations when syncing from upstream providers.
WalkthroughAdds a new ratio key Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (2)
controller/ratio_sync.go (1)
822-832: Update the docstring to mentioncreate_cache_ratio.The function comment enumerates the ratio outputs (
model_ratio,completion_ratio,cache_ratio) but nowcreate_cache_ratio = cache_write / input_costis also emitted. Minor, but keeps the contract accurate for future maintainers.📝 Proposed doc update
// model_ratio = input_cost_per_1M / 2 // completion_ratio = output_cost / input_cost // cache_ratio = cache_read_cost / input_cost +// create_cache_ratio = cache_write_cost / input_cost // // Duplicate model keys across providers are resolved by selecting the // cheapest non-zero input cost. If only zero-priced candidates exist, // a zero ratio is kept.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controller/ratio_sync.go` around lines 822 - 832, Update the docstring for convertModelsDevToRatioData to include the new emitted ratio create_cache_ratio and its formula; currently the comment lists model_ratio, completion_ratio, and cache_ratio but omits create_cache_ratio, so add a line like "create_cache_ratio = cache_write_cost / input_cost" (referencing create_cache_ratio) and ensure the docstring clearly lists all four outputs and their formulas to keep the contract accurate.web/src/pages/Setting/Ratio/UpstreamRatioSync.jsx (1)
328-340: Conflict description doesn't covercache_ratio/create_cache_ratio-only locals.
getLocalBillingCategory(Line 302-312) now returns'ratio'when a model only hasCacheRatioorCreateCacheRatioset locally, but thecurrentDesc/newDescbuilder below only renders模型倍率/补全倍率. In that edge case, the conflict modal will show模型倍率 : -,补全倍率 : -even though a real cache-related local value exists, which is confusing.Pre-existing issue for
CacheRatio, now broadened. Consider extending the description to include缓存倍率and缓存创建倍率when present (both forcurrentDescand thenewCat === 'ratio'branch ofnewDesc).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/pages/Setting/Ratio/UpstreamRatioSync.jsx` around lines 328 - 340, The conflict description misses cache-only locals: update the builders that produce currentDesc and newDesc to include cache fields when getLocalBillingCategory returns 'ratio' for cache-only models; specifically, in the currentDesc and the newCat === 'ratio' branch of newDesc, append display lines for CacheRatio (缓存倍率) and CreateCacheRatio (缓存创建倍率) using values from currentRatios (e.g., currentRatios.CacheRatio[model], currentRatios.CreateCacheRatio[model]) and from ratios (e.g., ratios['cache_ratio'], ratios['create_cache_ratio']), falling back to '-' when undefined, so the modal shows these cache values instead of empty dashes in cache-only cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@controller/ratio_sync.go`:
- Around line 822-832: Update the docstring for convertModelsDevToRatioData to
include the new emitted ratio create_cache_ratio and its formula; currently the
comment lists model_ratio, completion_ratio, and cache_ratio but omits
create_cache_ratio, so add a line like "create_cache_ratio = cache_write_cost /
input_cost" (referencing create_cache_ratio) and ensure the docstring clearly
lists all four outputs and their formulas to keep the contract accurate.
In `@web/src/pages/Setting/Ratio/UpstreamRatioSync.jsx`:
- Around line 328-340: The conflict description misses cache-only locals: update
the builders that produce currentDesc and newDesc to include cache fields when
getLocalBillingCategory returns 'ratio' for cache-only models; specifically, in
the currentDesc and the newCat === 'ratio' branch of newDesc, append display
lines for CacheRatio (缓存倍率) and CreateCacheRatio (缓存创建倍率) using values from
currentRatios (e.g., currentRatios.CacheRatio[model],
currentRatios.CreateCacheRatio[model]) and from ratios (e.g.,
ratios['cache_ratio'], ratios['create_cache_ratio']), falling back to '-' when
undefined, so the modal shows these cache values instead of empty dashes in
cache-only cases.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55092775-591d-4951-bab3-164b263291bd
📒 Files selected for processing (2)
controller/ratio_sync.goweb/src/pages/Setting/Ratio/UpstreamRatioSync.jsx
Align convertModelsDevToRatioData's docstring with its actual output by listing create_cache_ratio = cache_write_cost / input_cost alongside the other three emitted ratios, keeping the contract accurate.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
controller/ratio_sync.go (1)
798-820: Tie-breaker logic looks sound; consider weighting cache_write over cache_read.The new
cacheFieldCount-based preference correctly addresses resellers (e.g., 302ai) that mirror list pricing but drop cache metadata, so the authoritative upstream (Anthropic) wins on ties. One nit: counts are equally weighted, so a candidate exposing onlycache_readties with one exposing onlycache_write, and the lexicographic provider fallback decides. In practice both fields typically travel together, so this is unlikely to matter — just flagging in case a future provider publishes asymmetric metadata and you want a deterministic preference (e.g., prefer the candidate that hasCacheWriteset, since that's the new authoritative signal this PR relies on).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@controller/ratio_sync.go` around lines 798 - 820, The tie-breaker should prefer candidates that expose CacheWrite; update the comparison in the provider selection logic (the block that calls cacheFieldCount(current) and cacheFieldCount(next)) to first check if one candidate has CacheWrite and the other does not and return the one with CacheWrite, then fall back to CacheRead presence or the existing cacheFieldCount logic, and finally the existing lexicographic provider tie-breaker; alternatively, modify cacheFieldCount(modelsDevCandidate) to weight CacheWrite higher than CacheRead (e.g., add 2 for CacheWrite, 1 for CacheRead) so that candidates with CacheWrite rank above those with only CacheRead while leaving the rest of the comparison unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@controller/ratio_sync.go`:
- Around line 798-820: The tie-breaker should prefer candidates that expose
CacheWrite; update the comparison in the provider selection logic (the block
that calls cacheFieldCount(current) and cacheFieldCount(next)) to first check if
one candidate has CacheWrite and the other does not and return the one with
CacheWrite, then fall back to CacheRead presence or the existing cacheFieldCount
logic, and finally the existing lexicographic provider tie-breaker;
alternatively, modify cacheFieldCount(modelsDevCandidate) to weight CacheWrite
higher than CacheRead (e.g., add 2 for CacheWrite, 1 for CacheRead) so that
candidates with CacheWrite rank above those with only CacheRead while leaving
the rest of the comparison unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 129dc0ae-e007-4ec3-8b80-699db585ed0c
📒 Files selected for processing (1)
controller/ratio_sync.go
Important
📝 变更描述 / Description
本次 PR 为上游倍率同步功能增加了对 create_cache_ratio(缓存创建倍率) 的支持。
变更内容:
后端 (controller/ratio_sync.go):
create_cache_ratio添加到支持的 ratioTypes 列表中InputCacheWrite定价字段,转换为 create_cache_ratioCacheWrite字段到 cost/candidate 结构体,在价格候选者选择时优先选择包含更完整缓存元数据的候选者前端 (web/src/pages/Setting/Ratio/UpstreamRatioSync.jsx):
技术实现说明:
cache_write_price / prompt_price🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
备注:新版前端合并后需要移植
Summary by CodeRabbit
Release Notes