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 @@ -563,14 +563,6 @@ describe("AddModelPanel decision models", () => {

const decisionNotice = () => screen.queryByRole("note", { name: "Decision model notice" });

it("finds a provider by the name of one of its decision models", async () => {
const { user } = await setup();
await user.type(screen.getByRole("combobox", { name: /provider/i }), "jev");

expect(await screen.findByRole("option", { name: /TypeSafe/ })).toBeInTheDocument();
expect(screen.queryByRole("option", { name: /Anthropic/ })).not.toBeInTheDocument();
});

it("points a decision-only provider at the decision routes, the docs, and the playground", async () => {
const { user } = await setup();
await user.type(screen.getByRole("combobox", { name: /provider/i }), "TypeSafe");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import { authTypesFor } from "./provider_auth_types";
import { TEST_MODES } from "./add_model_modes";
import DecisionModelNote from "./DecisionModelNote";
import { decisionModelsSublabel, type DecisionCatalog } from "@/lib/decisionModels";
import { type DecisionCatalog } from "@/lib/decisionModels";
import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
import { credentialsKeys } from "@/app/(dashboard)/hooks/credentials/useCredentials";
import { extractProxyErrorMessage } from "@/lib/http/client";
Expand Down Expand Up @@ -86,7 +86,7 @@
teams,
credentials,
decisionCatalog,
}) => {

Check warning on line 89 in ui/litellm-dashboard/src/components/add_model/AddModelForm.tsx

View workflow job for this annotation

GitHub Actions / ui

Arrow function has a complexity of 31. Maximum allowed is 20
const [testMode, setTestMode] = useState<string>("chat");
const [isResultModalVisible, setIsResultModalVisible] = useState<boolean>(false);
const [isTestingConnection, setIsTestingConnection] = useState<boolean>(false);
Expand Down Expand Up @@ -156,7 +156,7 @@
useEffect(() => {
const fetchModelAccessGroups = async () => {
const response = await modelAvailableCall(accessToken, "", "", false, null, true, true);
setModelAccessGroups(response["data"].map((model: any) => model["id"]));

Check warning on line 159 in ui/litellm-dashboard/src/components/add_model/AddModelForm.tsx

View workflow job for this annotation

GitHub Actions / ui

Unexpected any. Specify a different type
};
fetchModelAccessGroups();
}, [accessToken]);
Expand All @@ -173,10 +173,9 @@
sortedProviderMetadata.map((providerInfo) => ({
label: providerInfo.provider_display_name,
value: providerInfo.provider,
sublabel: decisionModelsSublabel(decisionCatalog, providerInfo.litellm_provider),
icon: <ProviderLogo provider={providerInfo.provider} className="w-5 h-5" />,
})),
[sortedProviderMetadata, decisionCatalog],
[sortedProviderMetadata],
);

const pickedLitellmProvider = sortedProviderMetadata.find(
Expand Down Expand Up @@ -256,7 +255,7 @@
)}
</>
)}
{(isAdmin || (isTeamAdmin && teamAdminSelectedTeam)) && (

Check warning on line 258 in ui/litellm-dashboard/src/components/add_model/AddModelForm.tsx

View workflow job for this annotation

GitHub Actions / ui

Boolean expression combines 4 conditions; extract it into a named variable
<>
<MountedFormField
label={labelWithHint("Provider", "E.g. OpenAI, Azure OpenAI, Anthropic, Bedrock, etc.")}
Expand Down
26 changes: 1 addition & 25 deletions ui/litellm-dashboard/src/lib/decisionModels.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { describe, expect, it } from "vitest";
import {
EMPTY_DECISION_CATALOG,
buildDecisionCatalog,
decisionModelsSublabel,
isDecisionMode,
isDecisionSelection,
} from "./decisionModels";
import { EMPTY_DECISION_CATALOG, buildDecisionCatalog, isDecisionMode, isDecisionSelection } from "./decisionModels";

const COST_MAP = {
"typesafe/jev-latest": { litellm_provider: "typesafe", mode: "evaluation" },
Expand Down Expand Up @@ -46,12 +40,6 @@ describe("buildDecisionCatalog", () => {
);
});

it("strips the provider prefix from the names shown per provider", () => {
expect(catalog.providers.get("typesafe")?.names).toEqual(["jev-latest", "jev-preview"]);
expect(catalog.providers.get("perplexity")?.names).toEqual(["pplx-decider-v1-27b"]);
expect(catalog.providers.get("openai")?.names).toEqual(["gpt-6-luna"]);
});

it("marks a provider decision-only when every one of its models is a decision model", () => {
expect(catalog.providers.get("typesafe")?.decisionOnly).toBe(true);
expect(catalog.providers.get("somevendor")?.decisionOnly).toBe(true);
Expand All @@ -70,18 +58,6 @@ describe("buildDecisionCatalog", () => {
});
});

describe("decisionModelsSublabel", () => {
const catalog = buildDecisionCatalog(COST_MAP);

it("lists the provider's decision models", () => {
expect(decisionModelsSublabel(catalog, "typesafe")).toBe("Decision models: jev-latest, jev-preview");
});

it("is undefined for a provider with no decision models", () => {
expect(decisionModelsSublabel(catalog, "anthropic")).toBeUndefined();
});
});

describe("isDecisionSelection", () => {
const catalog = buildDecisionCatalog(COST_MAP);

Expand Down
14 changes: 1 addition & 13 deletions ui/litellm-dashboard/src/lib/decisionModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const costMapEntrySchema = z.object({
type CostMapEntry = z.infer<typeof costMapEntrySchema>;

interface ProviderDecisionModels {
readonly names: readonly string[];
readonly decisionOnly: boolean;
}

Expand All @@ -31,9 +30,6 @@ export const isDecisionMode = (mode: string | null | undefined): boolean => mode
const isDecisionEntry = (entry: CostMapEntry): boolean =>
isDecisionMode(entry.mode) || (entry.supported_endpoints ?? []).some((endpoint) => DECISION_ENDPOINTS.has(endpoint));

const withoutProviderPrefix = (key: string, provider: string): string =>
key.startsWith(`${provider}/`) ? key.slice(provider.length + 1) : key;

const parsedEntries = (costMap: unknown): ReadonlyArray<readonly [string, CostMapEntry]> => {
const record = z.record(z.string(), z.unknown()).safeParse(costMap);
if (!record.success) {
Expand All @@ -52,20 +48,12 @@ export function buildDecisionCatalog(costMap: unknown): DecisionCatalog {
const providers = new Map(
[...decisionProviders].map((provider) => {
const providerEntries = entries.filter(([, entry]) => entry.litellm_provider === provider);
const names = decisionEntries
.filter(([, entry]) => entry.litellm_provider === provider)
.map(([key]) => withoutProviderPrefix(key, provider));
return [provider, { names, decisionOnly: providerEntries.every(([, entry]) => isDecisionEntry(entry)) }] as const;
return [provider, { decisionOnly: providerEntries.every(([, entry]) => isDecisionEntry(entry)) }] as const;
}),
);
return { models: new Set(decisionEntries.map(([key]) => key)), providers };
}

export const decisionModelsSublabel = (catalog: DecisionCatalog, litellmProvider: string): string | undefined => {
const names = catalog.providers.get(litellmProvider)?.names ?? [];
return names.length > 0 ? `Decision models: ${names.join(", ")}` : undefined;
};

export const isDecisionSelection = (
catalog: DecisionCatalog,
litellmProvider: string | undefined,
Expand Down
Loading