fix(stats): map lab aliases
This commit is contained in:
parent
5c9e4ff21b
commit
85a79292e6
@ -63,17 +63,17 @@ export const getModelCatalog = query(async () => {
|
||||
}, "getModelCatalog")
|
||||
|
||||
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)
|
||||
return (
|
||||
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)
|
||||
)
|
||||
}
|
||||
|
||||
export function findModelCatalogLab(catalog: ModelCatalog, lab: string) {
|
||||
const id = catalogSlug(lab)
|
||||
const id = catalogLabSlug(lab)
|
||||
return catalog.labs.find((entry) => entry.id === id)
|
||||
}
|
||||
|
||||
@ -95,6 +95,8 @@ export function formatCatalogLabName(lab: string) {
|
||||
xai: "xAI",
|
||||
xiaomi: "Xiaomi",
|
||||
zai: "Z.ai",
|
||||
qwen: "Qwen",
|
||||
zhipu: "Zhipu",
|
||||
zhipuai: "Zhipu",
|
||||
}
|
||||
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("/")
|
||||
}
|
||||
|
||||
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> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value)
|
||||
}
|
||||
|
||||
@ -823,15 +823,14 @@ function resolveModelProvider(model: string, rows: StatMetricRow[], providerPara
|
||||
}
|
||||
|
||||
function providerMatches(provider: string, providerParam: string) {
|
||||
return modelSlug(provider) === modelSlug(providerParam)
|
||||
return providerSlug(provider) === providerSlug(providerParam)
|
||||
}
|
||||
|
||||
function resolveProviderName(providerParam: string, rows: StatMetricRow[]) {
|
||||
const input = providerParam.trim()
|
||||
if (!input) return undefined
|
||||
const inputSlug = modelSlug(input)
|
||||
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
|
||||
}
|
||||
|
||||
@ -848,6 +847,17 @@ function modelKey(provider: string, model: string) {
|
||||
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) {
|
||||
if (tokens <= 0 || costMicrocents <= 0) return 0
|
||||
return round((microcentsToDollars(costMicrocents) / tokens) * TOKEN_SCALE, 2)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user