From b613925ec8ba864ce601dfeacec18693202f6010 Mon Sep 17 00:00:00 2001 From: Ryan Crabbe Date: Mon, 2 Mar 2026 13:12:51 -0800 Subject: [PATCH] Add type safety for providersRequiringPrefix and tests for prefixWithProvider --- .../components/provider_info_helpers.test.tsx | 19 +++++++++++++++++++ .../src/components/provider_info_helpers.tsx | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx index 0e51d6b8175..929afce292d 100644 --- a/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx +++ b/ui/litellm-dashboard/src/components/provider_info_helpers.test.tsx @@ -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(() => {}); diff --git a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx index 1c016ec2924..8c7dadbfb95 100644 --- a/ui/litellm-dashboard/src/components/provider_info_helpers.tsx +++ b/ui/litellm-dashboard/src/components/provider_info_helpers.tsx @@ -368,7 +368,9 @@ export const getPlaceholder = (selectedProvider: string): string => { } }; -const providersRequiringPrefix = new Set(["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(_providersRequiringPrefix); export const prefixWithProvider = (provider: string, modelName: string): string => { if (!providersRequiringPrefix.has(provider)) return modelName;