mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
Merge 522bffb8d2 into 252c71c0b2
This commit is contained in:
commit
e061ecb6d7
2 changed files with 25 additions and 3 deletions
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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]));
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue