Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Tests and revert useAvailableModels

yuneng-jiang50dea2600fd0
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/ModelsAndEndpointsView.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/ModelsAndEndpointsView.test.tsx
index 630eecb3529..b165b71be7e 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/ModelsAndEndpointsView.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/ModelsAndEndpointsView.test.tsx
@@ -1,6 +1,7 @@
/* @vitest-environment jsdom */
import { render } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import ModelsAndEndpointsView from "./ModelsAndEndpointsView";
// Minimal stubs to avoid Next.js router and network usage during render
@@ -56,19 +57,24 @@ vi.mock("@/app/(dashboard)/hooks/useTeams", () => ({
}),
}));
+const createQueryClient = () =>
+ new QueryClient({
+ defaultOptions: { queries: { retry: false, gcTime: 0 } },
+ });
+
describe("ModelsAndEndpointsView", () => {
- it(
- "should render the models and endpoints view",
- async () => {
- // JSDOM polyfill for libraries expecting ResizeObserver (e.g., recharts)
- // Note: ResizeObserver is now globally mocked in setupTests.ts, but keeping this for backwards compatibility
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- (global as any).ResizeObserver = class {
- observe() {}
- unobserve() {}
- disconnect() {}
- };
- const { findByText } = render(
+ it("should render the models and endpoints view", async () => {
+ // JSDOM polyfill for libraries expecting ResizeObserver (e.g., recharts)
+ // Note: ResizeObserver is now globally mocked in setupTests.ts, but keeping this for backwards compatibility
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (global as any).ResizeObserver = class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ };
+ const queryClient = createQueryClient();
+ const { findByText } = render(
+ <QueryClientProvider client={queryClient}>
<ModelsAndEndpointsView
accessToken="123"
token="123"
@@ -79,10 +85,9 @@ describe("ModelsAndEndpointsView", () => {
setModelData={() => {}}
premiumUser={false}
teams={[]}
- />,
- );
- expect(await findByText("Model Management", {}, { timeout: 10000 })).toBeInTheDocument();
- },
- 15000,
- );
+ />
+ </QueryClientProvider>,
+ );
+ expect(await findByText("Model Management", {}, { timeout: 10000 })).toBeInTheDocument();
+ }, 15000);
});
diff --git a/ui/litellm-dashboard/src/components/molecules/models/ProviderLogo.test.tsx b/ui/litellm-dashboard/src/components/molecules/models/ProviderLogo.test.tsx
new file mode 100644
index 00000000000..9a9c631890b
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/molecules/models/ProviderLogo.test.tsx
@@ -0,0 +1,39 @@
+import React from "react";
+import { describe, it, expect, vi, beforeEach } from "vitest";
+import { screen, render, fireEvent, act } from "@testing-library/react";
+import { ProviderLogo } from "./ProviderLogo";
+import * as providerInfoHelpers from "../../provider_info_helpers";
+
+vi.mock("../../provider_info_helpers");
+
+describe("ProviderLogo", () => {
+ beforeEach(() => {
+ vi.resetAllMocks();
+ });
+
+ it("should render the component", () => {
+ vi.mocked(providerInfoHelpers.getProviderLogoAndName).mockReturnValue({
+ logo: "",
+ displayName: "Test Provider",
+ });
+ render(<ProviderLogo provider="test" />);
+ expect(screen.getByText("t")).toBeInTheDocument();
+ });
+
+ it("should show fallback when image fails to load", () => {
+ vi.mocked(providerInfoHelpers.getProviderLogoAndName).mockReturnValue({
+ logo: "/path/to/logo.png",
+ displayName: "Test Provider",
+ });
+ render(<ProviderLogo provider="test" />);
+ const img = screen.getByRole("img", { name: "test logo" });
+ expect(img).toBeInTheDocument();
+
+ act(() => {
+ fireEvent.error(img);
+ });
+
+ expect(screen.getByText("t")).toBeInTheDocument();
+ expect(screen.queryByRole("img")).not.toBeInTheDocument();
+ });
+});
diff --git a/ui/litellm-dashboard/src/components/playground/llm_calls/fetch_models.tsx b/ui/litellm-dashboard/src/components/playground/llm_calls/fetch_models.tsx
index ecbb607c563..14ba8c2381b 100644
--- a/ui/litellm-dashboard/src/components/playground/llm_calls/fetch_models.tsx
+++ b/ui/litellm-dashboard/src/components/playground/llm_calls/fetch_models.tsx
@@ -1,7 +1,6 @@
// fetch_models.ts
-import { useModelHub } from "@/app/(dashboard)/hooks/models/useModels";
-import { useMemo } from "react";
+import { modelHubCall } from "../../networking";
export interface ModelGroup {
model_group: string;
@@ -9,34 +8,26 @@ export interface ModelGroup {
}
/**
- * Hook that fetches available models using modelHubCall and formats them for the selection dropdown.
+ * Fetches available models using modelHubCall and formats them for the selection dropdown.
*/
-export const useAvailableModels = (
- accessToken: string | null,
-): {
- models: ModelGroup[];
- isLoading: boolean;
- error: Error | null;
-} => {
- const { data: fetchedModels, isLoading, error } = useModelHub(accessToken);
+export const fetchAvailableModels = async (accessToken: string): Promise<ModelGroup[]> => {
+ try {
+ const fetchedModels = await modelHubCall(accessToken);
+ console.log("model_info:", fetchedModels);
- const models = useMemo(() => {
- if (!fetchedModels?.data || fetchedModels.data.length === 0) {
- return [];
- }
-
- const formattedModels: ModelGroup[] = fetchedModels.data.map((item: any) => ({
- model_group: item.model_group,
- mode: item?.mode,
- }));
+ if (fetchedModels?.data.length > 0) {
+ const models: ModelGroup[] = fetchedModels.data.map((item: any) => ({
+ model_group: item.model_group, // Display the model_group to the user
+ mode: item?.mode, // Save the mode for auto-selection of endpoint type
+ }));
- formattedModels.sort((a, b) => a.model_group.localeCompare(b.model_group));
- return formattedModels;
- }, [fetchedModels]);
-
- return {
- models,
- isLoading,
- error: error as Error | null,
- };
+ // Sort models alphabetically by label
+ models.sort((a, b) => a.model_group.localeCompare(b.model_group));
+ return models;
+ }
+ return [];
+ } catch (error) {
+ console.error("Error fetching model info:", error);
+ throw error;
+ }
};