fix(stats): map lab aliases

This commit is contained in:
Adam
2026-06-17 05:38:14 -05:00
parent 5c9e4ff21b
commit 85a79292e6
2 changed files with 29 additions and 6 deletions
+16 -3
View File
@@ -63,17 +63,17 @@ export const getModelCatalog = query(async () => {
}, "getModelCatalog") }, "getModelCatalog")
export function findModelCatalogEntry(catalog: ModelCatalog, model: string, lab?: string) { export function findModelCatalogEntry(catalog: ModelCatalog, model: string, lab?: string) {
const normalizedId = lab ? `${catalogSlug(lab)}/${catalogSlug(model)}` : model.trim().toLowerCase() const normalizedId = lab ? `${catalogLabSlug(lab)}/${catalogSlug(model)}` : model.trim().toLowerCase()
const leaf = catalogSlug(model) const leaf = catalogSlug(model)
return ( return (
catalog.models.find((entry) => entry.id.toLowerCase() === normalizedId) ?? catalog.models.find((entry) => entry.id.toLowerCase() === normalizedId) ??
catalog.models.find((entry) => (lab ? entry.lab === catalogSlug(lab) : true) && entry.slug === leaf) ?? catalog.models.find((entry) => (lab ? entry.lab === catalogLabSlug(lab) : true) && entry.slug === leaf) ??
catalog.models.find((entry) => entry.slug === leaf) catalog.models.find((entry) => entry.slug === leaf)
) )
} }
export function findModelCatalogLab(catalog: ModelCatalog, lab: string) { export function findModelCatalogLab(catalog: ModelCatalog, lab: string) {
const id = catalogSlug(lab) const id = catalogLabSlug(lab)
return catalog.labs.find((entry) => entry.id === id) return catalog.labs.find((entry) => entry.id === id)
} }
@@ -95,6 +95,8 @@ export function formatCatalogLabName(lab: string) {
xai: "xAI", xai: "xAI",
xiaomi: "Xiaomi", xiaomi: "Xiaomi",
zai: "Z.ai", zai: "Z.ai",
qwen: "Qwen",
zhipu: "Zhipu",
zhipuai: "Zhipu", zhipuai: "Zhipu",
} }
return known[catalogSlug(lab)] ?? lab.replace(/[-_]/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase()) return known[catalogSlug(lab)] ?? lab.replace(/[-_]/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase())
@@ -273,6 +275,17 @@ function catalogIdKey(value: string) {
return value.split("/").map(catalogSlug).join("/") return value.split("/").map(catalogSlug).join("/")
} }
function catalogLabSlug(value: string) {
const slug = catalogSlug(value)
const aliases: Record<string, string> = {
moonshot: "moonshotai",
qwen: "alibaba",
zhipu: "zhipuai",
zai: "zhipuai",
}
return aliases[slug] ?? slug
}
function isRecord(value: unknown): value is Record<string, unknown> { function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value) return typeof value === "object" && value !== null && !Array.isArray(value)
} }
+13 -3
View File
@@ -823,15 +823,14 @@ function resolveModelProvider(model: string, rows: StatMetricRow[], providerPara
} }
function providerMatches(provider: string, providerParam: string) { function providerMatches(provider: string, providerParam: string) {
return modelSlug(provider) === modelSlug(providerParam) return providerSlug(provider) === providerSlug(providerParam)
} }
function resolveProviderName(providerParam: string, rows: StatMetricRow[]) { function resolveProviderName(providerParam: string, rows: StatMetricRow[]) {
const input = providerParam.trim() const input = providerParam.trim()
if (!input) return undefined if (!input) return undefined
const inputSlug = modelSlug(input)
return aggregateByModel(rows) return aggregateByModel(rows)
.filter((item) => modelSlug(item.provider) === inputSlug) .filter((item) => providerMatches(item.provider, input))
.toSorted((a, b) => b.totalTokens - a.totalTokens || a.provider.localeCompare(b.provider))[0]?.provider .toSorted((a, b) => b.totalTokens - a.totalTokens || a.provider.localeCompare(b.provider))[0]?.provider
} }
@@ -848,6 +847,17 @@ function modelKey(provider: string, model: string) {
return `${provider}\u0000${model}` return `${provider}\u0000${model}`
} }
function providerSlug(value: string) {
const slug = modelSlug(value)
const aliases: Record<string, string> = {
alibaba: "qwen",
moonshotai: "moonshot",
qwen: "qwen",
zhipuai: "zhipu",
}
return aliases[slug] ?? slug
}
function costPerMillion(costMicrocents: number, tokens: number) { function costPerMillion(costMicrocents: number, tokens: number) {
if (tokens <= 0 || costMicrocents <= 0) return 0 if (tokens <= 0 || costMicrocents <= 0) return 0
return round((microcentsToDollars(costMicrocents) / tokens) * TOKEN_SCALE, 2) return round((microcentsToDollars(costMicrocents) / tokens) * TOKEN_SCALE, 2)