fix(stats): merge renamed model data (#43883)
This commit is contained in:
@@ -41,6 +41,17 @@ describe("inference stat normalization", () => {
|
|||||||
expect(statProvider("unknown", "", "custom-provider")).toBe("custom-provider")
|
expect(statProvider("unknown", "", "custom-provider")).toBe("custom-provider")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("merges renamed models under their current name", () => {
|
||||||
|
expect(statModel("x-preview-f", "")).toBe("ox-alpha")
|
||||||
|
expect(statModel("xiaomi/mimo-v2.5", "")).toBe("mimo-v2.5")
|
||||||
|
expect(toModelAggregate(aggregate("x-preview-f", "openai"))).toMatchObject([
|
||||||
|
{
|
||||||
|
provider: "openai",
|
||||||
|
model: "ox-alpha",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
test("model aggregates prefer provider.model and use normalized model", () => {
|
test("model aggregates prefer provider.model and use normalized model", () => {
|
||||||
expect(toModelAggregate(aggregate("alpha-gpt-next", "openai"))).toEqual([])
|
expect(toModelAggregate(aggregate("alpha-gpt-next", "openai"))).toEqual([])
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
EXCLUDED_MODELS,
|
EXCLUDED_MODELS,
|
||||||
FREE_MODELS,
|
FREE_MODELS,
|
||||||
MODEL_AUTHOR_RULES,
|
MODEL_AUTHOR_RULES,
|
||||||
|
MODEL_NAME_ALIASES,
|
||||||
RETIRED_STAT_PROVIDERS,
|
RETIRED_STAT_PROVIDERS,
|
||||||
statModel,
|
statModel,
|
||||||
statProvider,
|
statProvider,
|
||||||
@@ -302,6 +303,9 @@ function statPeriods(grain: "day" | "week", periodStart: Date, periodEnd: Date)
|
|||||||
function statModelSql(model: string, providerModel: string) {
|
function statModelSql(model: string, providerModel: string) {
|
||||||
return `COALESCE(NULLIF(regexp_replace(CASE
|
return `COALESCE(NULLIF(regexp_replace(CASE
|
||||||
WHEN lower(${model}) = 'big-pickle' THEN regexp_replace(NULLIF(${providerModel}, ''), '^.*/', '')
|
WHEN lower(${model}) = 'big-pickle' THEN regexp_replace(NULLIF(${providerModel}, ''), '^.*/', '')
|
||||||
|
${Object.entries(MODEL_NAME_ALIASES)
|
||||||
|
.map(([from, to]) => ` WHEN lower(${model}) = ${sqlString(from)} THEN ${sqlString(to)}`)
|
||||||
|
.join("\n")}
|
||||||
ELSE ${model}
|
ELSE ${model}
|
||||||
END, '(-free|:free|:global)+$', ''), ''), 'unknown')`
|
END, '(-free|:free|:global)+$', ''), ''), 'unknown')`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,11 @@ export const MODEL_AUTHOR_RULES = [
|
|||||||
] as const
|
] as const
|
||||||
export const EXCLUDED_MODELS = new Set(["alpha-gpt-next"])
|
export const EXCLUDED_MODELS = new Set(["alpha-gpt-next"])
|
||||||
export const FREE_MODELS = new Set(["gpt-5-nano", "grok-code", "big-pickle"])
|
export const FREE_MODELS = new Set(["gpt-5-nano", "grok-code", "big-pickle"])
|
||||||
export const RETIRED_STAT_MODELS = ["big-pickle"]
|
export const MODEL_NAME_ALIASES: Record<string, string> = {
|
||||||
|
"x-preview-f": "ox-alpha",
|
||||||
|
"xiaomi/mimo-v2.5": "mimo-v2.5",
|
||||||
|
}
|
||||||
|
export const RETIRED_STAT_MODELS = ["big-pickle", ...Object.keys(MODEL_NAME_ALIASES)]
|
||||||
export const RETIRED_STAT_PROVIDERS = ["opencode"]
|
export const RETIRED_STAT_PROVIDERS = ["opencode"]
|
||||||
|
|
||||||
export function normalizeInferenceModel(value: string | undefined) {
|
export function normalizeInferenceModel(value: string | undefined) {
|
||||||
@@ -31,6 +35,8 @@ export function modelAuthor(value: string | undefined) {
|
|||||||
|
|
||||||
export function statModel(model: string | undefined, providerModel: string | undefined) {
|
export function statModel(model: string | undefined, providerModel: string | undefined) {
|
||||||
const normalized = normalizeInferenceModel(model)
|
const normalized = normalizeInferenceModel(model)
|
||||||
|
const alias = MODEL_NAME_ALIASES[normalized.toLowerCase()]
|
||||||
|
if (alias) return alias
|
||||||
if (RETIRED_STAT_MODELS.includes(normalized.toLowerCase()))
|
if (RETIRED_STAT_MODELS.includes(normalized.toLowerCase()))
|
||||||
return normalizeInferenceModel(providerModel?.split("/").at(-1))
|
return normalizeInferenceModel(providerModel?.split("/").at(-1))
|
||||||
return normalized
|
return normalized
|
||||||
|
|||||||
Reference in New Issue
Block a user