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]

[Feature] UI - Include Model Access Group Models on Team Models Table (#16298)

yuneng-jiangb1be6185acd9
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.test.tsx
new file mode 100644
index 00000000000..6ec3945a499
--- /dev/null
+++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.test.tsx
@@ -0,0 +1,251 @@
+import { render, screen, waitFor } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { describe, it, expect, beforeAll, vi, beforeEach } from "vitest";
+import AllModelsTab from "./AllModelsTab";
+import * as useTeamsModule from "@/app/(dashboard)/hooks/useTeams";
+import * as useAuthorizedModule from "@/app/(dashboard)/hooks/useAuthorized";
+
+// Mock window.matchMedia for Ant Design components
+beforeAll(() => {
+ Object.defineProperty(window, "matchMedia", {
+ writable: true,
+ value: (query: string) => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: () => {},
+ removeListener: () => {},
+ addEventListener: () => {},
+ removeEventListener: () => {},
+ dispatchEvent: () => false,
+ }),
+ });
+});
+
+describe("AllModelsTab", () => {
+ const mockSetSelectedModelGroup = vi.fn();
+ const mockSetSelectedModelId = vi.fn();
+ const mockSetSelectedTeamId = vi.fn();
+ const mockSetEditModel = vi.fn();
+
+ const defaultProps = {
+ selectedModelGroup: "all",
+ setSelectedModelGroup: mockSetSelectedModelGroup,
+ availableModelGroups: ["gpt-4", "gpt-3.5-turbo"],
+ availableModelAccessGroups: ["sales-team", "engineering-team"],
+ setSelectedModelId: mockSetSelectedModelId,
+ setSelectedTeamId: mockSetSelectedTeamId,
+ setEditModel: mockSetEditModel,
+ modelData: {
+ data: [],
+ },
+ };
+
+ const mockUseAuthorized = {
+ token: "mock-token",
+ accessToken: "mock-access-token",
+ userId: "user-123",
+ userEmail: "[email protected]",
+ userRole: "Admin",
+ premiumUser: true,
+ disabledPersonalKeyCreation: false,
+ showSSOBanner: false,
+ };
+
+ beforeAll(() => {
+ // Mock useAuthorized hook
+ vi.spyOn(useAuthorizedModule, "default").mockReturnValue(mockUseAuthorized);
+ });
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it("should render with empty data", () => {
+ // Mock useTeams hook
+ vi.spyOn(useTeamsModule, "default").mockReturnValue({
+ teams: [],
+ setTeams: vi.fn(),
+ });
+
+ const { container } = render(<AllModelsTab {...defaultProps} />);
+ expect(container).toBeTruthy();
+ expect(screen.getByText("Current Team:")).toBeInTheDocument();
+ });
+
+ it("should filter models by direct team access when current team is selected", async () => {
+ const user = userEvent.setup();
+ const mockTeams = [
+ {
+ team_id: "team-456",
+ team_alias: "Engineering Team",
+ models: ["gpt-4"],
+ max_budget: null,
+ budget_duration: null,
+ tpm_limit: null,
+ rpm_limit: null,
+ organization_id: "org-123",
+ created_at: "2024-01-01",
+ keys: [],
+ members_with_roles: [],
+ },
+ ];
+
+ // Mock useTeams hook with team data
+ vi.spyOn(useTeamsModule, "default").mockReturnValue({
+ teams: mockTeams,
+ setTeams: vi.fn(),
+ });
+
+ const modelData = {
+ data: [
+ {
+ model_name: "gpt-4-accessible",
+ model_info: {
+ id: "model-1",
+ access_via_team_ids: ["team-456"], // Direct team access
+ access_groups: [],
+ },
+ },
+ {
+ model_name: "gpt-3.5-turbo-blocked",
+ model_info: {
+ id: "model-2",
+ access_via_team_ids: ["team-789"], // Different team
+ access_groups: [],
+ },
+ },
+ ],
+ };
+
+ render(<AllModelsTab {...defaultProps} modelData={modelData} />);
+
+ // Initially on "personal" team, should show 0 results (no models have direct_access)
+ expect(screen.getByText("Showing 0 results")).toBeInTheDocument();
+
+ // Click on the team selector to change to Engineering Team
+ const teamSelector = screen.getAllByRole("button").find((btn) => btn.textContent?.includes("Personal"));
+ expect(teamSelector).toBeInTheDocument();
+
+ await user.click(teamSelector!);
+
+ // Click on Engineering Team option
+ await waitFor(async () => {
+ const engineeringOption = await screen.findByText(/Engineering Team/);
+ await user.click(engineeringOption);
+ });
+
+ // After selecting Engineering Team, should show 1 result (gpt-4-accessible has direct team access)
+ await waitFor(() => {
+ expect(screen.getByText("Showing 1 - 1 of 1 results")).toBeInTheDocument();
+ });
+ });
+
+ it("should filter models by access group matching when team models match model access groups", async () => {
+ const user = userEvent.setup();
+ const mockTeams = [
+ {
+ team_id: "team-sales",
+ team_alias: "Sales Team",
+ models: ["sales-model-group"], // Team has this model group
+ max_budget: null,
+ budget_duration: null,
+ tpm_limit: null,
+ rpm_limit: null,
+ organization_id: "org-123",
+ created_at: "2024-01-01",
+ keys: [],
+ members_with_roles: [],
+ },
+ ];
+
+ // Mock useTeams hook
+ vi.spyOn(useTeamsModule, "default").mockReturnValue({
+ teams: mockTeams,
+ setTeams: vi.fn(),
+ });
+
+ const modelData = {
+ data: [
+ {
+ model_name: "gpt-4-sales",
+ model_info: {
+ id: "model-sales-1",
+ access_via_team_ids: [], // No direct team access
+ access_groups: ["sales-model-group"], // But has access group that matches team's models
+ },
+ },
+ {
+ model_name: "gpt-4-engineering",
+ model_info: {
+ id: "model-eng-1",
+ access_via_team_ids: [],
+ access_groups: ["engineering-model-group"], // Different access group
+ },
+ },
+ ],
+ };
+
+ render(<AllModelsTab {...defaultProps} modelData={modelData} />);
+
+ // Initially on "personal" team, should show 0 results
+ expect(screen.getByText("Showing 0 results")).toBeInTheDocument();
+
+ // Click on the team selector
+ const teamSelector = screen.getAllByRole("button").find((btn) => btn.textContent?.includes("Personal"));
+ expect(teamSelector).toBeInTheDocument();
+
+ await user.click(teamSelector!);
+
+ // Click on Sales Team option
+ await waitFor(async () => {
+ const salesOption = await screen.findByText(/Sales Team/);
+ await user.click(salesOption);
+ });
+
+ // After selecting Sales Team, should show 1 result (gpt-4-sales has matching access group)
+ await waitFor(() => {
+ expect(screen.getByText("Showing 1 - 1 of 1 results")).toBeInTheDocument();
+ });
+ });
+
+ it("should filter models by direct_access for personal team", async () => {
+ // Mock useTeams hook
+ vi.spyOn(useTeamsModule, "default").mockReturnValue({
+ teams: [],
+ setTeams: vi.fn(),
+ });
+
+ const modelData = {
+ data: [
+ {
+ model_name: "gpt-4-personal",
+ model_info: {
+ id: "model-personal-1",
+ direct_access: true, // Available for personal use
+ access_via_team_ids: [],
+ access_groups: [],
+ },
+ },
+ {
+ model_name: "gpt-4-team-only",
+ model_info: {
+ id: "model-team-1",
+ direct_access: false, // Not available for personal use
+ access_via_team_ids: ["team-123"],
+ access_groups: [],
+ },
+ },
+ ],
+ };
+
+ render(<AllModelsTab {...defaultProps} modelData={modelData} />);
+
+ // When currentTeam is "personal" (default), it should filter by direct_access === true
+ // This tests the personal access logic in lines 72-73
+ // Should show 1 result (only gpt-4-personal with direct_access=true)
+ await waitFor(() => {
+ expect(screen.getByText("Showing 1 - 1 of 1 results")).toBeInTheDocument();
+ });
+ });
+});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.tsx b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.tsx
index 43632de6eda..87fa0b1e3b6 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/models-and-endpoints/components/AllModelsTab.tsx
@@ -1,12 +1,13 @@
-import { Grid, Select, SelectItem, TabPanel, Text } from "@tremor/react";
-import { InfoCircleOutlined } from "@ant-design/icons";
+import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
+import useTeams from "@/app/(dashboard)/hooks/useTeams";
+import { Team } from "@/components/key_team_helpers/key_list";
import { ModelDataTable } from "@/components/model_dashboard/table";
import { columns } from "@/components/molecules/models/columns";
import { getDisplayModelName } from "@/components/view_model/model_name_display";
-import React, { useEffect, useMemo, useRef, useState } from "react";
-import useTeams from "@/app/(dashboard)/hooks/useTeams";
-import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized";
-import { Table as TableInstance, PaginationState } from "@tanstack/react-table";
+import { InfoCircleOutlined } from "@ant-design/icons";
+import { PaginationState, Table as TableInstance } from "@tanstack/react-table";
+import { Grid, Select, SelectItem, TabPanel, Text } from "@tremor/react";
+import { useEffect, useMemo, useRef, useState } from "react";
type ModelViewMode = "all" | "current_team";
@@ -36,7 +37,7 @@ const AllModelsTab = ({
const [modelNameSearch, setModelNameSearch] = useState<string>("");
const [modelViewMode, setModelViewMode] = useState<ModelViewMode>("current_team");
- const [currentTeam, setCurrentTeam] = useState<string>("personal"); // 'personal' or team_id
+ const [currentTeam, setCurrentTeam] = useState<Team | "personal">("personal");
const [showFilters, setShowFilters] = useState<boolean>(false);
const [selectedModelAccessGroupFilter, setSelectedModelAccessGroupFilter] = useState<string | null>(null);
const [expandedRows, setExpandedRows] = useState<Set<string>>(new Set());
@@ -71,7 +72,15 @@ const AllModelsTab = ({
if (currentTeam === "personal") {
teamAccessMatch = model.model_info?.direct_access === true;
} else {
- teamAccessMatch = model.model_info?.access_via_team_ids?.includes(currentTeam) === true;
+ // Check if model is directly associated with the team via team_ids
+ const directTeamAccess = model.model_info?.access_via_team_ids?.includes(currentTeam.team_id) === true;
+
+ // Check if any of the team's models match the model's access groups
+ const accessGroupMatch =
+ currentTeam.models?.some((teamModel: string) => model.model_info?.access_groups?.includes(teamModel)) ===
+ true;
+
+ teamAccessMatch = directTeamAccess || accessGroupMatch;
}
}
@@ -111,8 +120,15 @@ const AllModelsTab = ({
<Select
className="w-80"
defaultValue="personal"
- value={currentTeam}
- onValueChange={(value) => setCurrentTeam(value)}
+ value={currentTeam === "personal" ? "personal" : currentTeam.team_id}
+ onValueChange={(value) => {
+ if (value === "personal") {
+ setCurrentTeam("personal");
+ } else {
+ const team = teams?.find((t) => t.team_id === value);
+ if (team) setCurrentTeam(team);
+ }
+ }}
>
<SelectItem value="personal">
<div className="flex items-center gap-2">
@@ -178,7 +194,8 @@ const AllModelsTab = ({
) : (
<span>
To access these models: Create a Virtual Key and select Team as &quot;
- {currentTeam}&quot; on the{" "}
+ {typeof currentTeam !== "string" ? currentTeam.team_alias || currentTeam.team_id : ""}&quot; on
+ the{" "}
<a
href="/public?login=success&page=api-keys"
className="text-gray-600 hover:text-gray-800 underline"
diff --git a/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_speech.test.tsx b/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_speech.test.tsx
index 9a9c733fe5b..dbfe8a39959 100644
--- a/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_speech.test.tsx
+++ b/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_speech.test.tsx
@@ -11,6 +11,7 @@ describe("audio_speech", () => {
const mockCreate = vi.fn();
const mockUpdateUI = vi.fn();
const mockBlob = new Blob(["mock audio data"], { type: "audio/mpeg" });
+ let abortController: AbortController | null = null;
beforeEach(() => {
// Mock the response structure from OpenAI audio speech API
@@ -29,6 +30,11 @@ describe("audio_speech", () => {
});
afterEach(() => {
+ // Clean up abort controller if it exists
+ if (abortController) {
+ abortController.abort();
+ abortController = null;
+ }
vi.clearAllMocks();
});
@@ -47,7 +53,8 @@ describe("audio_speech", () => {
});
it("should include optional parameters when provided", async () => {
- const signal = new AbortController().signal;
+ abortController = new AbortController();
+ const signal = abortController.signal;
await makeOpenAIAudioSpeechRequest(
"Test input",
diff --git a/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_transcriptions.test.tsx b/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_transcriptions.test.tsx
index 60b606ca5bb..65b11e7f7d8 100644
--- a/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_transcriptions.test.tsx
+++ b/ui/litellm-dashboard/src/components/chat_ui/llm_calls/audio_transcriptions.test.tsx
@@ -7,6 +7,7 @@ vi.mock("openai");
describe("audio_transcription", () => {
const mockCreate = vi.fn();
const mockUpdateUI = vi.fn();
+ let abortController: AbortController | null = null;
beforeEach(() => {
// Mock the response structure from OpenAI audio transcription API
@@ -25,6 +26,11 @@ describe("audio_transcription", () => {
});
afterEach(() => {
+ // Clean up abort controller if it exists
+ if (abortController) {
+ abortController.abort();
+ abortController = null;
+ }
vi.clearAllMocks();
});
@@ -49,7 +55,8 @@ describe("audio_transcription", () => {
const mockFile = new File(["audio data"], "test.mp3", {
type: "audio/mpeg",
});
- const signal = new AbortController().signal;
+ abortController = new AbortController();
+ const signal = abortController.signal;
await makeOpenAIAudioTranscriptionRequest(
mockFile,