Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe("UnityGatewayChatProvider models", () => {
expect(models).toEqual([
{
id: "system.ai.gpt-5",
name: "gpt-5",
name: "GPT 5",
family: "gpt-5",
version: "1",
detail: "Databricks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ describe("UnityGatewayModels", () => {
expect(state).toEqual({
status: "ready",
value: [
{ id: "system.ai.claude-sonnet", name: "claude-sonnet", family: "claude-sonnet" },
{ id: "system.ai.gpt-5", name: "gpt-5", family: "gpt-5" },
{ id: "system.ai.claude-sonnet", name: "Claude Sonnet", family: "claude-sonnet" },
{ id: "system.ai.gpt-5", name: "GPT 5", family: "gpt-5" },
],
});
const [listing] = s.listings();
Expand All @@ -101,6 +101,52 @@ describe("UnityGatewayModels", () => {
expect(url.searchParams.get("parent")).toBe("schemas/system.ai");
});

it("names each model for the picker from its service name, with acronyms in capitals", async () => {
const s = setup(() => ({
body: {
model_services: responses(
"system.ai.claude-sonnet-5-5",
"system.ai.3-foo",
"system.ai.dbrx-instruct",
"system.ai.gpt-5.1-codex",
"system.ai.glm-4-7",
"system.ai.llama-4-maverick",
"system.ai.model-2026-01-15",
),
},
}));
await s.gateway.signIn("ug");

expect((await s.models.list()).map(({ id, name }) => [id, name])).toEqual([
["system.ai.3-foo", "3 Foo"],
["system.ai.claude-sonnet-5-5", "Claude Sonnet 5.5"],
["system.ai.dbrx-instruct", "DBRX Instruct"],
["system.ai.glm-4-7", "GLM 4.7"],
["system.ai.gpt-5.1-codex", "GPT 5.1 Codex"],
["system.ai.llama-4-maverick", "Llama 4 Maverick"],
["system.ai.model-2026-01-15", "Model 2026.01.15"],
]);
});

it("shows the ids of models whose names would be the same", async () => {
const s = setup(() => ({
body: {
model_services: responses(
"system.ai.gpt-5-1",
"system.ai.gpt-5.1",
"system.ai.gpt-6",
),
},
}));
await s.gateway.signIn("ug");

expect((await s.models.list()).map((m) => m.name)).toEqual([
"GPT 6",
"system.ai.gpt-5-1",
"system.ai.gpt-5.1",
]);
});

it("adds the token limits the gateway reports to the models it reports them for", async () => {
const s = setup(
() => ({
Expand Down Expand Up @@ -139,14 +185,14 @@ describe("UnityGatewayModels", () => {
expect(await s.models.list()).toStrictEqual([
{
id: "system.ai.claude-opus-5-5",
name: "claude-opus-5-5",
name: "Claude Opus 5.5",
family: "claude-opus-5-5",
limits: { input: 1_000_000, output: 128_000 },
},
{ id: "system.ai.gemini-3-pro", name: "gemini-3-pro", family: "gemini-3-pro" },
{ id: "system.ai.gemini-3-pro", name: "Gemini 3 Pro", family: "gemini-3-pro" },
{
id: "system.ai.model-a",
name: "model-a",
name: "Model A",
family: "model-a",
limits: { input: 922_000, output: 128_000 },
},
Expand All @@ -169,7 +215,7 @@ describe("UnityGatewayModels", () => {
await s.gateway.signIn("ug");

expect(await s.models.list()).toStrictEqual([
{ id: "system.ai.a", name: "a", family: "a" },
{ id: "system.ai.a", name: "A", family: "a" },
]);
expect(s.warnings()).toMatchObject([
{ message: "Can't list Unity Gateway's model token limits" },
Expand All @@ -186,7 +232,7 @@ describe("UnityGatewayModels", () => {
const models = new UnityGatewayModels(s.gateway.state, log, undefined, 20);
await s.gateway.signIn("ug");

expect(await models.list()).toStrictEqual([{ id: "system.ai.a", name: "a", family: "a" }]);
expect(await models.list()).toStrictEqual([{ id: "system.ai.a", name: "A", family: "a" }]);
expect(log.entries.map((e) => [e.level, e.message])).toEqual([
["warn", "Unity Gateway didn't list its model token limits within 0.02 seconds"],
]);
Expand Down Expand Up @@ -218,8 +264,8 @@ describe("UnityGatewayModels", () => {
await s.gateway.signIn("ug");

expect(await s.models.list()).toEqual([
{ id: "system.ai.a", name: "a", family: "a" },
{ id: "system.ai.b", name: "b", family: "b" },
{ id: "system.ai.a", name: "A", family: "a" },
{ id: "system.ai.b", name: "B", family: "b" },
]);
expect(s.listings()).toHaveLength(2);
});
Expand All @@ -233,13 +279,13 @@ describe("UnityGatewayModels", () => {
},
}));
await s.gateway.signIn("ug");
expect((await s.models.list()).map((m) => m.name)).toEqual(["on-b"]);
expect((await s.models.list()).map((m) => m.name)).toEqual(["On B"]);
await s.models.list();
expect(s.listings()).toHaveLength(1);

await s.gateway.signIn("DEFAULT");

expect((await s.models.list()).map((m) => m.name)).toEqual(["on-a"]);
expect((await s.models.list()).map((m) => m.name)).toEqual(["On A"]);
expect(s.listings()).toHaveLength(2);
});

Expand Down Expand Up @@ -277,7 +323,7 @@ describe("UnityGatewayModels", () => {

fail = false;

expect((await s.models.list()).map((m) => m.name)).toEqual(["a"]);
expect((await s.models.list()).map((m) => m.name)).toEqual(["A"]);
expect(s.listings()).toHaveLength(3);
});

Expand Down Expand Up @@ -334,7 +380,7 @@ describe("UnityGatewayModels", () => {

const models = new UnityGatewayModels(s.gateway.state, fakeLog());

expect((await models.list()).map((m) => m.name)).toEqual(["a"]);
expect((await models.list()).map((m) => m.name)).toEqual(["A"]);
expect(s.listings()).toHaveLength(2);
models.dispose();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const UNITY_GATEWAY_VENDOR = "databricks";
export interface UnityGatewayModel {
/** The model service, for example `system.ai.claude-sonnet`. */
readonly id: string;
/** The id without the `system.ai.` prefix. */
/** A readable name for the model picker, `Claude Sonnet` for `system.ai.claude-sonnet`. */
readonly name: string;
readonly family: string;
/** The context window and output limit the gateway reports; most models have none. */
Expand Down Expand Up @@ -165,8 +165,55 @@ async function listModels(
models.push(model);
}
}
models.sort((a, b) => a.name.localeCompare(b.name));
return models;
return withUniqueNames(models).sort((a, b) => a.name.localeCompare(b.name));
}

// Two models the picker can't tell apart are worse than ids it can.
function withUniqueNames(models: readonly UnityGatewayModel[]): UnityGatewayModel[] {
const counts = new Map<string, number>();
for (const { name } of models) {
counts.set(name, (counts.get(name) ?? 0) + 1);
}
return models.map((model) =>
(counts.get(model.name) ?? 0) > 1 ? { ...model, name: model.id } : model,
);
}

// A word with no vowel is read letter by letter, so title case would misspell
// it (`Gpt`); this holds for any acronym, without a list of known ones.
const ACRONYM = /^(?=.*[a-z])[^aeiouy]+$/;

/**
* The picker name for a model service: without its namespace, the words
* title-cased (acronyms in capitals), and a run of numeric segments joined
* into a dotted version, so `system.ai.claude-sonnet-5-5` is `Claude Sonnet 5.5`.
*/
function modelDisplayName(id: string): string {
// Only the namespace is dropped: a dot after it is part of a version (`gpt-5.1`).
const stem = id.replace(/^system\.ai\./, "");
const words: string[] = [];
let version: string[] = [];
for (const segment of stem.split("-")) {
if (/^\d+$/.test(segment)) {
version.push(segment);
continue;
}
if (version.length > 0) {
words.push(version.join("."));
version = [];
}
if (segment !== "") {
words.push(
ACRONYM.test(segment)
? segment.toUpperCase()
: segment.charAt(0).toUpperCase() + segment.slice(1),
);
}
}
if (version.length > 0) {
words.push(version.join("."));
}
return words.length > 0 ? words.join(" ") : stem;
}

function withLimits(
Expand All @@ -185,5 +232,5 @@ function toModel(service: ModelService): UnityGatewayModel | undefined {
if (!service.supportedApiTypes?.includes("mlflow/v1/responses") || !id) {
return undefined;
}
return { id, name: id.replace(/^system\.ai\./, ""), family: id.split(".").at(-1) ?? id };
return { id, name: modelDisplayName(id), family: id.split(".").at(-1) ?? id };
}
Loading