mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-22 03:03:28 +00:00
fix(stats): prefer Go catalog pricing (#43120)
This commit is contained in:
parent
42fc297d30
commit
728ae7c949
2 changed files with 49 additions and 1 deletions
47
packages/stats/app/src/routes/model-catalog.test.ts
Normal file
47
packages/stats/app/src/routes/model-catalog.test.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { describe, expect, mock, test } from "bun:test"
|
||||
|
||||
mock.module("@solidjs/router", () => ({ query: (load: () => unknown) => load }))
|
||||
|
||||
const { buildModelCatalog, findModelCatalogEntry } = await import("./model-catalog")
|
||||
|
||||
describe("model catalog pricing", () => {
|
||||
test("prefers OpenCode Go pricing over a zero-cost coding plan with the same model id", () => {
|
||||
const catalog = buildModelCatalog(
|
||||
{
|
||||
models: {
|
||||
"zhipuai/glm-5.3": {
|
||||
id: "zhipuai/glm-5.3",
|
||||
name: "GLM-5.3",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"opencode-go": {
|
||||
id: "opencode-go",
|
||||
models: {
|
||||
"glm-5.3": {
|
||||
id: "glm-5.3",
|
||||
cost: { input: 1.4, output: 4.4, cache_read: 0.26 },
|
||||
},
|
||||
},
|
||||
},
|
||||
"zhipuai-coding-plan": {
|
||||
id: "zhipuai-coding-plan",
|
||||
models: {
|
||||
"glm-5.3": {
|
||||
id: "glm-5.3",
|
||||
cost: { input: 0, output: 0, cache_read: 0 },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
expect(findModelCatalogEntry(catalog, "glm-5.3")?.cost).toEqual({
|
||||
input: 1.4,
|
||||
output: 4.4,
|
||||
cacheRead: 0.26,
|
||||
cacheWrite: undefined,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -119,7 +119,7 @@ export function catalogSlug(value: string) {
|
|||
.replace(/-{2,}/g, "-")
|
||||
}
|
||||
|
||||
function buildModelCatalog(payload: unknown, pricingPayload?: unknown, labPayload?: unknown): ModelCatalog {
|
||||
export function buildModelCatalog(payload: unknown, pricingPayload?: unknown, labPayload?: unknown): ModelCatalog {
|
||||
const costs = readCatalogCosts(pricingPayload)
|
||||
const labDescriptions = readCatalogLabDescriptions(payload, pricingPayload, labPayload)
|
||||
const models = readCatalogModels(payload)
|
||||
|
|
@ -129,6 +129,7 @@ function buildModelCatalog(payload: unknown, pricingPayload?: unknown, labPayloa
|
|||
cost:
|
||||
costs.get(catalogIdKey(model.id)) ??
|
||||
costs.get(`${model.lab}/${model.slug}`) ??
|
||||
costs.get(`opencode-go/${model.slug}`) ??
|
||||
costs.get(model.slug) ??
|
||||
model.cost,
|
||||
}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue