Expose per-model group ratios on the public PLG pricing payload - #692
Merged
Conversation
Billing resolves a model's discount through GetEffectiveGroupRatio, which checks GroupModelRatio (group x model) before falling back to the flat group ratio. The public PLG payload only carried the flat ratio, so any model priced below its group — a domestic model set to 0.6 while plg sits at 0.9, say — was quoted on /models at a price higher than it is charged. buildWebsitePublicGroupPricingPayload now emits group_model_ratio, reusing filterGroupModelRatioByUsableGroupsAndModels so the map is restricted to the plg group and to models the payload actually exposes. Models removed by the hidden-models filter drop out of the ratio map too, since it is built from the already-filtered pricing list. pricing_version moves to website-public-plg-v2. No website change was needed: enrichVendorNames already folds group_model_ratio into each model's group_ratio via buildEffectiveGroupRatio, and getBestGroupRatio reads from there. The override simply never arrived. Tests were added on both sides to pin the precedence — per-model first, group ratio second — so the wiring cannot silently regress. This is display-only. Actual billing already applied the override.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
后端计费按模型级倍率优先、分组倍率兜底的顺序取折扣,但官网
/models只拿得到分组倍率。一旦某个模型(比如国产模型)单独配了比分组更低的价,页面会按更高的价报出去。证据
计费路径
relay/helper/price.go:47→ratio_setting.GetEffectiveGroupRatio(userGroup, usingGroup, model),优先级(setting/ratio_setting/group_ratio.go:170):GetGroupModelRatio(usingGroup, model)— 分组 × 模型GetGroupGroupRatio(userGroup, usingGroup)GetGroupRatio(usingGroup)— plg = 0.9命中第 1 层就返回,不再看第 3 层。
plg 用户的 token 被强制锁在
group = "plg"(controller/token.go:573),所以走的正是GetEffectiveGroupRatio("plg", "plg", model)。线上
?group=plg的 payload 实测:对比不带 group 的默认 payload —— 它是有
group_model_ratio的(buildWebsitePricingPayloadDefault)。只有buildWebsitePublicGroupPricingPayload这条漏了。假设给
glm-5配GroupModelRatio.plg = 0.6(model_ratio = 0.3):线上目前
group_model_ratio为null(尚未配置任何模型级倍率),所以还没暴雷 —— 但机制是坏的,一配就出问题。改动
buildWebsitePublicGroupPricingPayload补上group_model_ratio,复用既有的filterGroupModelRatioByUsableGroupsAndModels:pricing_version升为website-public-plg-v2。前端零改动
enrichVendorNames(pricing-page.tsx:1174)本来就调buildEffectiveGroupRatio把模型级倍率合进model.group_ratio,getBestGroupRatio/getMinGroupRatio也从那里读 —— 前端逻辑一直是对的,只是这个字段从没送到过。新增的前端测试全部一次通过,正好证明了这点。
验证
后端
新增 2 个测试:
TestBuildWebsitePublicGroupPricingPayloadExposesGroupModelRatio—— 断言只下发 plg 分组、只含可见模型(vip分组和不可见模型都被剔除)TestBuildWebsitePublicGroupPricingPayloadOmitsHiddenModelRatios—— 断言隐藏模型的倍率不泄漏同步更新了
TestBuildWebsitePublicGroupPricingPayloadIncludesHiddenPLGOnly的 JSON 断言(新增字段 + 版本号)。前端
新增 5 个测试(
group-model-ratio-pricing.test.ts)钉住优先级:buildEffectiveGroupRatio/getBestGroupRatio/formatModelPrice/ 目录表格行,外加一个"未 enrich 时回退分组倍率"的对照。既有失败(与本 PR 无关,已对照验证)
go test ./controller/全量有TestAssetTaskWorkerFailsClosedWhenQueuedUserIsNoLongerUsable失败 —— stash 后在干净 main 上单跑,同样 FAILnext/server模块缺失的环境问题,此前多次确认基线相同部署
Router deploy: not required —— 只改了controller/pricing.go里公开定价 payload 的构造,不触及/v1、relay、provider 路由、计费结算或共享中间件。GetGroupModelRatioCopy是只读取快照。Other deploy targets:newapi-console(/api/website/pricing由控制台服务提供)。website 无代码改动,但要等新 payload 才生效。Risk / validation: 纯展示修正,不改变任何实际扣费。上线后核对/api/website/pricing?group=plg返回中含group_model_ratio且pricing_version为website-public-plg-v2;配一个模型级倍率后确认/zh/models显示的是折后价。多节点: 无状态读取,各节点从同一份 option 快照构造,不涉及跨节点协调。该分支绕过websitePricingCache(响应头no-store),无缓存一致性问题。