mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
Add type safety for providersRequiringPrefix and tests for prefixWithProvider
This commit is contained in:
parent
8cc5f0194d
commit
b613925ec8
2 changed files with 22 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import {
|
|||
getPlaceholder,
|
||||
getProviderLogoAndName,
|
||||
getProviderModels,
|
||||
prefixWithProvider,
|
||||
providerLogoMap,
|
||||
provider_map,
|
||||
} from "./provider_info_helpers";
|
||||
|
|
@ -165,6 +166,24 @@ describe("provider_info_helpers", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("prefixWithProvider", () => {
|
||||
it("should prefix Azure models with azure/", () => {
|
||||
expect(prefixWithProvider("Azure", "my-deployment")).toBe("azure/my-deployment");
|
||||
});
|
||||
|
||||
it("should prefix OpenAI_Compatible models with openai/", () => {
|
||||
expect(prefixWithProvider("OpenAI_Compatible", "my-model")).toBe("openai/my-model");
|
||||
});
|
||||
|
||||
it("should prefix OpenAI_Text_Compatible models with text-completion-openai/", () => {
|
||||
expect(prefixWithProvider("OpenAI_Text_Compatible", "my-model")).toBe("text-completion-openai/my-model");
|
||||
});
|
||||
|
||||
it("should not prefix providers that don't require it", () => {
|
||||
expect(prefixWithProvider("Anthropic", "claude-3-opus")).toBe("claude-3-opus");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getProviderModels", () => {
|
||||
const consoleSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
|
||||
|
|
|
|||
|
|
@ -368,7 +368,9 @@ export const getPlaceholder = (selectedProvider: string): string => {
|
|||
}
|
||||
};
|
||||
|
||||
const providersRequiringPrefix = new Set<string>(["Azure", "OpenAI_Compatible", "OpenAI_Text_Compatible"]);
|
||||
// Typed as enum keys so renames cause compile-time errors (values can't be used since e.g. OpenAI_Compatible resolves to a display string, not the provider_map key)
|
||||
const _providersRequiringPrefix: (keyof typeof Providers)[] = ["Azure", "OpenAI_Compatible", "OpenAI_Text_Compatible"];
|
||||
const providersRequiringPrefix = new Set<string>(_providersRequiringPrefix);
|
||||
|
||||
export const prefixWithProvider = (provider: string, modelName: string): string => {
|
||||
if (!providersRequiringPrefix.has(provider)) return modelName;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue