This commit is contained in:
Rayan Salhab 2026-09-19 14:17:23 -04:00 committed by GitHub
commit e061ecb6d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View file

@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { getModelDisplayName } from "./fetch_available_models_team_key";
import { getModelDisplayName, unfurlWildcardModelsInList } from "./fetch_available_models_team_key";
describe("getModelDisplayName", () => {
it("should return display label for all proxy models", () => {
@ -11,3 +11,25 @@ describe("getModelDisplayName", () => {
expect(getModelDisplayName("openai/*")).toBe("All openai models");
});
});
describe("unfurlWildcardModelsInList", () => {
it("should expand wildcard models while preserving display names and removing duplicates", () => {
expect(
unfurlWildcardModelsInList(
["openai/*", "anthropic/claude-4", "openai/gpt-4"],
["openai/gpt-4", "openai/gpt-4o", "anthropic/claude-4"],
),
).toEqual(["openai/*", "openai/gpt-4", "openai/gpt-4o", "anthropic/claude-4"]);
});
it("should not exceed the call stack when expanding a wildcard with many matching models", () => {
const allModels = Array.from({ length: 150_000 }, (_, index) => `openai/model-${index}`);
const result = unfurlWildcardModelsInList(["openai/*"], allModels);
expect(result).toHaveLength(allModels.length + 1);
expect(result[0]).toBe("openai/*");
expect(result[1]).toBe("openai/model-0");
expect(result.at(-1)).toBe("openai/model-149999");
});
});

View file

@ -63,7 +63,7 @@ export const unfurlWildcardModelsInList = (teamModels: string[], allModels: stri
// Find all models that start with this provider
const matchingModels = allModels.filter((model) => model.startsWith(provider + "/"));
expandedModels.push(...matchingModels);
matchingModels.forEach((model) => expandedModels.push(model));
wildcardDisplayNames.push(teamModel);
} else {
expandedModels.push(teamModel);
@ -71,5 +71,5 @@ export const unfurlWildcardModelsInList = (teamModels: string[], allModels: stri
});
// Combine arrays with wildcard display names first, then remove duplicates
return [...wildcardDisplayNames, ...expandedModels].filter((item, index, array) => array.indexOf(item) === index);
return Array.from(new Set([...wildcardDisplayNames, ...expandedModels]));
};