mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-06 16:50:28 +00:00
模型广场:上下文档位统一标签形态并保证升序
- 阶梯表标签由计费层统一生成:有上限的档为「≤上限」、末档为「>下限」 (达到阈值即进高档时用 < / ≥),不再沿用渠道区间的自定义 tier_label; 合并同价段只看单价 - 前端档位按下限升序兜底展示,无标签时按同一形态生成
This commit is contained in:
1 parent
377d1230fc
commit
ecce0769c0
4 files changed
+55
-73
No files matched your search
@@ -381,14 +381,19 @@ function hasOfficialCache(o: NonNullable<PlazaModel['official_pricing']>): boole
|
||||
return o.cache_write_price != null || o.cache_read_price != null || o.cache_write_1h_price != null
|
||||
}
|
||||
|
||||
/** 上下文档位按下限升序展示(后端已升序,此处兜底)。 */
|
||||
function sortByContext(intervals: UserPricingInterval[]): UserPricingInterval[] {
|
||||
return [...intervals].sort((a, b) => a.min_tokens - b.min_tokens)
|
||||
}
|
||||
|
||||
/** token 模式的阶梯定价(内联进输入/输出/缓存列)。 */
|
||||
function tokenIntervals(m: PlazaModel): UserPricingInterval[] {
|
||||
return m.pricing?.intervals ?? []
|
||||
return sortByContext(m.pricing?.intervals ?? [])
|
||||
}
|
||||
|
||||
/** 官方阶梯(后端按目录规则合成,不受分组开关影响)。 */
|
||||
function officialIntervals(m: PlazaModel): UserPricingInterval[] {
|
||||
return m.official_pricing?.intervals ?? []
|
||||
return sortByContext(m.official_pricing?.intervals ?? [])
|
||||
}
|
||||
|
||||
/** 任一档带缓存价才按档渲染缓存列;否则沿用平价的写入/读取两行。 */
|
||||
@@ -409,18 +414,14 @@ function requestIntervals(m: PlazaModel): UserPricingInterval[] {
|
||||
return (m.pricing?.intervals ?? []).filter((iv) => iv.per_request_price != null)
|
||||
}
|
||||
|
||||
/** 档位标签:优先管理员配置的 tier_label,否则按 token 区间生成(≤200K / >200K / 100–200K / 200K–1M)。 */
|
||||
/**
|
||||
* 档位标签:优先后端/管理员给出的 tier_label,否则按区间生成统一形态——
|
||||
* 有上限为「≤上限」,末档为「>下限」;档位升序排列,相邻的 ≤100K / ≤200K 即表示 (100K,200K]。
|
||||
*/
|
||||
function tierLabel(iv: UserPricingInterval): string {
|
||||
if (iv.tier_label) return iv.tier_label
|
||||
const { min_tokens: min, max_tokens: max } = iv
|
||||
if (max == null) return `>${formatTokenCount(min)}`
|
||||
if (min === 0) return `≤${formatTokenCount(max)}`
|
||||
const lo = formatTokenCount(min)
|
||||
const hi = formatTokenCount(max)
|
||||
// 同单位时省略前一个单位(100–200K),节省列宽
|
||||
const unit = hi.slice(-1)
|
||||
if (/[KM]/.test(unit) && lo.endsWith(unit)) return `${lo.slice(0, -1)}–${hi}`
|
||||
return `${lo}–${hi}`
|
||||
return max == null ? `>${formatTokenCount(min)}` : `≤${formatTokenCount(max)}`
|
||||
}
|
||||
|
||||
function formatTokenCount(n: number): string {
|
||||
|
||||
@@ -507,23 +507,21 @@ describe('PlazaModelPricingTable 长上下文阶梯', () => {
|
||||
expect(marginal.findAll('tbody td')[0].text()).toContain('modelPlaza.table.marginalBadge')
|
||||
})
|
||||
|
||||
it('自定义中间档标签同单位时省略前一个单位', () => {
|
||||
it('无标签的多档按区间生成统一形态(≤上限 / >下限),并按下限升序展示', () => {
|
||||
const model = ladderModel({
|
||||
pricing: {
|
||||
...ladderModel().pricing!,
|
||||
// 故意乱序:展示必须按上下文从低到高
|
||||
intervals: [
|
||||
{ ...ladderIntervals()[0], max_tokens: 100000, tier_label: '' },
|
||||
{ ...ladderIntervals()[1], min_tokens: 1000000, tier_label: '' },
|
||||
{ ...ladderIntervals()[0], min_tokens: 100000, max_tokens: 200000, tier_label: '' },
|
||||
{ ...ladderIntervals()[1], min_tokens: 200000, max_tokens: 1000000, tier_label: '' },
|
||||
{ ...ladderIntervals()[1], min_tokens: 1000000, tier_label: '' }
|
||||
{ ...ladderIntervals()[0], max_tokens: 100000, tier_label: '' },
|
||||
{ ...ladderIntervals()[1], min_tokens: 200000, max_tokens: 1000000, tier_label: '' }
|
||||
]
|
||||
}
|
||||
})
|
||||
const text = mountTable([model], 1).findAll('tbody td')[1].text()
|
||||
expect(text).toContain('≤100K')
|
||||
expect(text).toContain('100–200K')
|
||||
expect(text).toContain('200K–1M')
|
||||
expect(text).toContain('>1M')
|
||||
const rows = mountTable([model], 1).findAll('tbody td')[1].findAll('.leading-5')
|
||||
expect(rows.map((r) => r.text().split(/\s+/)[0])).toEqual(['≤100K', '≤200K', '≤1M', '>1M'])
|
||||
})
|
||||
|
||||
it('官方无 intervals 字段(旧响应)时官方列保持平价,实付无阶梯时缓存列保持两行', () => {
|
||||
|
||||
Reference in new issue
Block a user