repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/model-info/model-label.ts
Rawfunction basename(modelId: string): string {
return modelId.split("/").at(-1) ?? modelId;
}
function withoutTrailingQualifiers(
value: string,
qualifiers: ReadonlySet<string>,
): string {
const parts = value.split("-");
while (parts.length > 0 && qualifiers.has(parts.at(-1)?.toLowerCase() ?? ""))
parts.pop();
return parts.join("-");
}
const GEMINI_QUALIFIERS = new Set([
"customtools",
"image",
"latest",
"live",
"preview",
]);
const HIGHSPEED_QUALIFIER = new Set(["highspeed"]);
const KIMI_QUALIFIERS = new Set(["highspeed", "preview", "turbo"]);
const RELEASE_QUALIFIERS = new Set(["latest"]);
/** Compact a model ID according to its family's stable naming grammar. */
export function shortModelLabel(modelId: string): string {
const id = basename(modelId);
let match: RegExpExecArray | null;
match = /^gpt-(\d+(?:\.\d+)*)(?:-(.+))?$/iu.exec(id);
if (match) return match[2] ?? id;
match = /^claude-([^-]+)-\d/iu.exec(id);
if (match) return match[1] ?? id;
match = /^gemini-(\d+(?:\.\d+)?)-(.+)$/iu.exec(id);
if (match) {
const variant = withoutTrailingQualifiers(
match[2] ?? "",
GEMINI_QUALIFIERS,
);
return variant ? `${match[1]}-${variant}` : id;
}
match = /^gemini-(.+)$/iu.exec(id);
if (match)
return withoutTrailingQualifiers(match[1] ?? id, GEMINI_QUALIFIERS);
if (/^grok-\d/iu.test(id)) return id;
match = /^deepseek-(v?\d+(?:\.\d+)?)-(flash|pro)(?:-|$)/iu.exec(id);
if (match) return `${match[1]}-${match[2]}`;
match = /^minimax-(m\d+(?:\.\d+)?)(?:-(.+))?$/iu.exec(id);
if (match) return match[1] ?? id;
match = /^kimi-(k\d+(?:\.\d+)?)(?:-(.+))?$/iu.exec(id);
if (match) {
const variant = withoutTrailingQualifiers(match[2] ?? "", KIMI_QUALIFIERS);
return variant ? `${match[1]}-${variant}` : (match[1] ?? id);
}
if (/^kimi-for-coding(?:-highspeed)?$/iu.test(id)) return "kimi-coding";
match = /^glm-(\d+(?:\.\d+)?)(?:-(.+))?$/iu.exec(id);
if (match) {
const variant = withoutTrailingQualifiers(
match[2] ?? "",
HIGHSPEED_QUALIFIER,
);
return `glm-${match[1]}${variant ? `-${variant}` : ""}`;
}
if (
/^(?:codestral|devstral|magistral|ministral|mistral|pixtral|voxtral)-/iu.test(
id,
)
) {
const withoutRelease = id.replace(/-(?:\d{4}|\d{8})$/u, "");
return withoutTrailingQualifiers(withoutRelease, RELEASE_QUALIFIERS);
}
return id;
}