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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Feature] UI - Add tags in model creation (#16138)
yuneng-jiangdd053e1d1268
diff --git a/ui/litellm-dashboard/src/components/add_model/add_model_tab.tsx b/ui/litellm-dashboard/src/components/add_model/add_model_tab.tsxindex 26c5e5c3ff6..faf14c96a89 100644--- a/ui/litellm-dashboard/src/components/add_model/add_model_tab.tsx+++ b/ui/litellm-dashboard/src/components/add_model/add_model_tab.tsx@@ -9,7 +9,7 @@ import ProviderSpecificFields from "./provider_specific_fields";import AdvancedSettings from "./advanced_settings";import { Providers, providerLogoMap } from "../provider_info_helpers";import type { Team } from "../key_team_helpers/key_list";-import { CredentialItem, getGuardrailsList, modelAvailableCall } from "../networking";+import { CredentialItem, getGuardrailsList, modelAvailableCall, tagListCall } from "../networking";import ConnectionErrorDisplay from "./model_connection_test";import { TEST_MODES } from "./add_model_modes";import { Row, Col } from "antd";@@ -18,6 +18,7 @@ import TeamDropdown from "../common_components/team_dropdown";import { all_admin_roles } from "@/utils/roles";import AddAutoRouterTab from "./add_auto_router_tab";import { handleAddAutoRouterSubmit } from "./handle_add_auto_router_submit";+import { Tag } from "../tag_management/types";interface AddModelTabProps {form: FormInstance; // For the Add Model tab@@ -63,6 +64,7 @@ const AddModelTab: React.FC<AddModelTabProps> = ({const [isResultModalVisible, setIsResultModalVisible] = useState<boolean>(false);const [isTestingConnection, setIsTestingConnection] = useState<boolean>(false);const [guardrailsList, setGuardrailsList] = useState<string[]>([]);+ const [tagsList, setTagsList] = useState<Record<string, Tag>>({});// Using a unique ID to force the ConnectionErrorDisplay to remount and run a fresh testconst [connectionTestId, setConnectionTestId] = useState<string>("");@@ -80,6 +82,19 @@ const AddModelTab: React.FC<AddModelTabProps> = ({fetchGuardrails();}, [accessToken]);+ useEffect(() => {+ const fetchTags = async () => {+ try {+ const response = await tagListCall(accessToken);+ setTagsList(response);+ } catch (error) {+ console.error("Failed to fetch tags:", error);+ }+ };++ fetchTags();+ }, [accessToken]);+// Test connection when button is clickedconst handleTestConnection = async () => {setIsTestingConnection(true);@@ -349,6 +364,7 @@ const AddModelTab: React.FC<AddModelTabProps> = ({setShowAdvancedSettings={setShowAdvancedSettings}teams={teams}guardrailsList={guardrailsList}+ tagsList={tagsList}/><div className="flex justify-between items-center mb-4">diff --git a/ui/litellm-dashboard/src/components/add_model/advanced_settings.test.tsx b/ui/litellm-dashboard/src/components/add_model/advanced_settings.test.tsxnew file mode 100644index 00000000000..8c2e339141f--- /dev/null+++ b/ui/litellm-dashboard/src/components/add_model/advanced_settings.test.tsx@@ -0,0 +1,34 @@+import { fireEvent, render, waitFor } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";+import AdvancedSettings from "./advanced_settings";++describe("AdvancedSettings", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });+ it("should render", () => {+ render(+ <AdvancedSettings+ showAdvancedSettings={true}+ setShowAdvancedSettings={() => {}}+ guardrailsList={[]}+ tagsList={{}}+ />,+ );+ });++ it("should render tags list", async () => {+ const { getByText } = render(+ <AdvancedSettings+ showAdvancedSettings={true}+ setShowAdvancedSettings={() => {}}+ guardrailsList={[]}+ tagsList={{}}+ />,+ );+ fireEvent.click(getByText("Advanced Settings"));+ await waitFor(() => {+ expect(getByText("Tags")).toBeInTheDocument();+ });+ });+});diff --git a/ui/litellm-dashboard/src/components/add_model/advanced_settings.tsx b/ui/litellm-dashboard/src/components/add_model/advanced_settings.tsxindex e77dc55f75d..7314b5d9c46 100644--- a/ui/litellm-dashboard/src/components/add_model/advanced_settings.tsx+++ b/ui/litellm-dashboard/src/components/add_model/advanced_settings.tsx@@ -6,6 +6,7 @@ import TextArea from "antd/es/input/TextArea";import { InfoCircleOutlined } from "@ant-design/icons";import { Team } from "../key_team_helpers/key_list";import CacheControlSettings from "./cache_control_settings";+import { Tag } from "../tag_management/types";const { Link } = Typography;interface AdvancedSettingsProps {@@ -13,6 +14,7 @@ interface AdvancedSettingsProps {setShowAdvancedSettings: (show: boolean) => void;teams?: Team[] | null;guardrailsList: string[];+ tagsList: Record<string, Tag>;}const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({@@ -20,6 +22,7 @@ const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({setShowAdvancedSettings,teams,guardrailsList,+ tagsList,}) => {const [form] = Form.useForm();const [customPricing, setCustomPricing] = React.useState(false);@@ -145,6 +148,19 @@ const AdvancedSettings: React.FC<AdvancedSettingsProps> = ({/></Form.Item>+ <Form.Item label="Tags" name="tags" className="mb-4">+ <Select+ mode="tags"+ style={{ width: "100%" }}+ placeholder="Select or enter tags"+ options={Object.values(tagsList).map((tag) => ({+ value: tag.name,+ label: tag.name,+ title: tag.description || tag.name,+ }))}+ />+ </Form.Item>+{customPricing && (<div className="ml-6 pl-4 border-l-2 border-gray-200"><Form.Item label="Pricing Model" name="pricing_model" className="mb-4">diff --git a/ui/litellm-dashboard/tests/setupTests.ts b/ui/litellm-dashboard/tests/setupTests.tsindex 21474441f2c..0232a28ac5f 100644--- a/ui/litellm-dashboard/tests/setupTests.ts+++ b/ui/litellm-dashboard/tests/setupTests.ts@@ -13,3 +13,18 @@ vi.spyOn(Date.prototype, "toLocaleString").mockImplementation(function (this: Daconst pad = (n: number) => String(n).padStart(2, "0");return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;});++// Fixed matchMedia not found error in tests: https://github.com/vitest-dev/vitest/issues/821+Object.defineProperty(window, "matchMedia", {+ writable: true,+ value: (query: string) => ({+ matches: false,+ media: query,+ onchange: null,+ addListener: vi.fn(),+ removeListener: vi.fn(),+ addEventListener: vi.fn(),+ removeEventListener: vi.fn(),+ dispatchEvent: vi.fn(),+ }),+});