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]

[Fix] UI - Revert Changes for Test Key Multiple Model Select (#16372)

yuneng-jiang99a8a304c1dc
diff --git a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx
index 3a2b4860eaa..376c56b1327 100644
--- a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx
+++ b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { fireEvent, getByText, render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import ChatUI from "./ChatUI";
import * as fetchModelsModule from "./llm_calls/fetch_models";
@@ -49,55 +49,10 @@ describe("ChatUI", () => {
disabledPersonalKeyCreation={false}
/>,
);
-
- await waitFor(() => {
- expect(getByText("Test Key")).toBeInTheDocument();
- });
- });
-
- it("should render the chat UI with selected models", async () => {
- const { getByText, container, getAllByText } = render(
- <ChatUI
- accessToken="1234567890"
- token="1234567890"
- userRole="user"
- userID="1234567890"
- disabledPersonalKeyCreation={false}
- />,
- );
-
- await waitFor(() => {
- expect(getByText("Test Key")).toBeInTheDocument();
- });
-
- // Wait for the first model to be auto-selected (default behavior)
- await waitFor(() => {
- expect(getByText("Model 1")).toBeInTheDocument();
- });
-
- // Now click the Select dropdown to open it and check other models
- const selectComponent = container.querySelectorAll(".ant-select-selector")[1]; // Second select is for models
- expect(selectComponent).toBeTruthy();
-
- // Click to open the dropdown
- fireEvent.mouseDown(selectComponent!);
-
- // Wait for dropdown to open and check for all models
- await waitFor(() => {
- const dropdown = document.querySelector(".ant-select-dropdown");
- expect(dropdown).toBeTruthy();
-
- // All three models should be in the dropdown as options
- // Use getAllByTitle since Ant Design Select renders options with title attributes
- const model2Elements = screen.queryAllByText("Model 2");
- const model3Elements = screen.queryAllByText("Model 3");
-
- expect(model2Elements.length).toBeGreaterThan(0);
- expect(model3Elements.length).toBeGreaterThan(0);
- });
+ expect(getByText("Test Key")).toBeInTheDocument();
});
- it("should allow users to pick multiple models and render badges for selected models", async () => {
+ it("should show the voice selector when the endpoint type is audio_speech", async () => {
const { getByText, container } = render(
<ChatUI
accessToken="1234567890"
@@ -108,66 +63,46 @@ describe("ChatUI", () => {
/>,
);
+ // Wait for the component to render
await waitFor(() => {
expect(getByText("Test Key")).toBeInTheDocument();
});
- await waitFor(() => {
- expect(getByText("Model 1")).toBeInTheDocument();
- });
-
- const selectComponent = container.querySelectorAll(".ant-select-selector")[1];
- expect(selectComponent).toBeTruthy();
-
- fireEvent.mouseDown(selectComponent!);
+ // Find the endpoint selector by looking for the "Endpoint Type:" text and its associated Select
+ const endpointTypeText = getByText("Endpoint Type:");
+ const selectContainer = endpointTypeText.parentElement;
+ const selectElement = selectContainer?.querySelector(".ant-select-selector");
- let model2Option: HTMLElement | null = null;
- await waitFor(() => {
- const dropdown = document.querySelector(".ant-select-dropdown");
- expect(dropdown).toBeTruthy();
- const options = document.querySelectorAll(".ant-select-item-option-content");
- model2Option = Array.from(options).find((opt) => opt.textContent === "Model 2") as HTMLElement;
- expect(model2Option).toBeTruthy();
- });
+ expect(selectElement).toBeInTheDocument();
- fireEvent.click(model2Option!);
+ // Click on the select to open the dropdown
+ if (selectElement) {
+ fireEvent.mouseDown(selectElement);
+ }
+ // Wait for the dropdown to appear and find the audio_speech option
await waitFor(() => {
- const model1Badges = screen.getAllByText("Model 1");
- const model2Badges = screen.getAllByText("Model 2");
-
- expect(model1Badges.length).toBeGreaterThan(0);
- expect(model2Badges.length).toBeGreaterThan(0);
+ const audioSpeechOption = screen.getByText("/v1/audio/speech");
+ expect(audioSpeechOption).toBeInTheDocument();
});
- fireEvent.mouseDown(selectComponent!);
+ // Click on the audio_speech option
+ const audioSpeechOption = screen.getByText("/v1/audio/speech");
+ fireEvent.click(audioSpeechOption);
- let model3Option: HTMLElement | null = null;
+ // Verify the voice selector appears
await waitFor(() => {
- const dropdown = document.querySelector(".ant-select-dropdown");
- expect(dropdown).toBeTruthy();
- const options = document.querySelectorAll(".ant-select-item-option-content");
- model3Option = Array.from(options).find((opt) => opt.textContent === "Model 3") as HTMLElement;
- expect(model3Option).toBeTruthy();
+ expect(getByText("Voice")).toBeInTheDocument();
});
- fireEvent.click(model3Option!);
-
- // Verify all three models have badges rendered
- await waitFor(() => {
- const model1Badges = screen.getAllByText("Model 1");
- const model2Badges = screen.getAllByText("Model 2");
- const model3Badges = screen.getAllByText("Model 3");
-
- expect(model1Badges.length).toBeGreaterThan(0);
- expect(model2Badges.length).toBeGreaterThan(0);
- expect(model3Badges.length).toBeGreaterThan(0);
- });
- const tags = container.querySelectorAll(".ant-tag");
- expect(tags.length).toBe(3);
+ // Verify the voice select component is present
+ const voiceText = getByText("Voice");
+ const voiceSelectContainer = voiceText.parentElement;
+ const voiceSelectElement = voiceSelectContainer?.querySelector(".ant-select");
+ expect(voiceSelectElement).toBeInTheDocument();
});
- it("should manage selectedModels state and its side effects", async () => {
+ it("should allow the user to select a model", async () => {
const { getByText, container } = render(
<ChatUI
accessToken="1234567890"
@@ -178,6 +113,7 @@ describe("ChatUI", () => {
/>,
);
+ // Wait for the component to render
await waitFor(() => {
expect(getByText("Test Key")).toBeInTheDocument();
});
@@ -186,109 +122,14 @@ describe("ChatUI", () => {
expect(getByText("Model 1")).toBeInTheDocument();
});
- await waitFor(() => {
- const storedModels = sessionStorage.getItem("selectedModels");
- expect(storedModels).toBeTruthy();
- const parsedModels = JSON.parse(storedModels!);
- expect(parsedModels).toContain("Model 1");
- });
-
const selectComponent = container.querySelectorAll(".ant-select-selector")[1];
+ expect(selectComponent).toBeTruthy();
fireEvent.mouseDown(selectComponent!);
- let model2Option: HTMLElement | null = null;
- await waitFor(() => {
- const dropdown = document.querySelector(".ant-select-dropdown");
- expect(dropdown).toBeTruthy();
- const options = document.querySelectorAll(".ant-select-item-option-content");
- model2Option = Array.from(options).find((opt) => opt.textContent === "Model 2") as HTMLElement;
- expect(model2Option).toBeTruthy();
- });
-
- fireEvent.click(model2Option!);
-
- await waitFor(() => {
- const model2Badges = screen.getAllByText("Model 2");
- expect(model2Badges.length).toBeGreaterThan(0);
- });
-
- await waitFor(() => {
- const storedModels = sessionStorage.getItem("selectedModels");
- const parsedModels = JSON.parse(storedModels!);
- expect(parsedModels).toContain("Model 1");
- expect(parsedModels).toContain("Model 2");
- expect(parsedModels.length).toBe(2);
- });
-
- const tags = container.querySelectorAll(".ant-tag");
- expect(tags.length).toBe(2);
-
- const firstTagCloseButton = tags[0].querySelector(".ant-tag-close-icon");
- expect(firstTagCloseButton).toBeTruthy();
- fireEvent.click(firstTagCloseButton!);
-
- await waitFor(() => {
- const storedModels = sessionStorage.getItem("selectedModels");
- const parsedModels = JSON.parse(storedModels!);
- expect(parsedModels).not.toContain("Model 1");
- expect(parsedModels).toContain("Model 2");
- expect(parsedModels.length).toBe(1);
- });
-
- await waitFor(() => {
- const remainingTags = container.querySelectorAll(".ant-tag");
- expect(remainingTags.length).toBe(1);
- });
- });
-
- it("should show the voice selector when the endpoint type is audio_speech", async () => {
- const { getByText, container } = render(
- <ChatUI
- accessToken="1234567890"
- token="1234567890"
- userRole="user"
- userID="1234567890"
- disabledPersonalKeyCreation={false}
- />,
- );
-
- // Wait for the component to render
await waitFor(() => {
- expect(getByText("Test Key")).toBeInTheDocument();
+ const model1Label = screen.getAllByText("Model 1");
+ expect(model1Label.length).toBeGreaterThan(0);
});
-
- // Find the endpoint selector by looking for the "Endpoint Type:" text and its associated Select
- const endpointTypeText = getByText("Endpoint Type:");
- const selectContainer = endpointTypeText.parentElement;
- const selectElement = selectContainer?.querySelector(".ant-select-selector");
-
- expect(selectElement).toBeInTheDocument();
-
- // Click on the select to open the dropdown
- if (selectElement) {
- fireEvent.mouseDown(selectElement);
- }
-
- // Wait for the dropdown to appear and find the audio_speech option
- await waitFor(() => {
- const audioSpeechOption = screen.getByText("/v1/audio/speech");
- expect(audioSpeechOption).toBeInTheDocument();
- });
-
- // Click on the audio_speech option
- const audioSpeechOption = screen.getByText("/v1/audio/speech");
- fireEvent.click(audioSpeechOption);
-
- // Verify the voice selector appears
- await waitFor(() => {
- expect(getByText("Voice")).toBeInTheDocument();
- });
-
- // Verify the voice select component is present
- const voiceText = getByText("Voice");
- const voiceSelectContainer = voiceText.parentElement;
- const voiceSelectElement = voiceSelectContainer?.querySelector(".ant-select");
- expect(voiceSelectElement).toBeInTheDocument();
});
});
diff --git a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.tsx b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.tsx
index f0e8bfb1aff..809c7493eb8 100644
--- a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.tsx
+++ b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.tsx
@@ -1,7 +1,3 @@
-import { Card, Text, TextInput, Title, Button as TremorButton } from "@tremor/react";
-import React, { useEffect, useRef, useState } from "react";
-import ReactMarkdown from "react-markdown";
-import { v4 as uuidv4 } from "uuid";
import {
ApiOutlined,
ArrowUpOutlined,
@@ -21,9 +17,13 @@ import {
ToolOutlined,
UserOutlined,
} from "@ant-design/icons";
-import { Button, Input, Modal, Select, Spin, Tag, Tooltip, Typography, Upload } from "antd";
+import { Card, Text, TextInput, Title, Button as TremorButton } from "@tremor/react";
+import { Button, Input, Modal, Select, Spin, Tooltip, Typography, Upload } from "antd";
+import React, { useEffect, useRef, useState } from "react";
+import ReactMarkdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { coy } from "react-syntax-highlighter/dist/esm/styles/prism";
+import { v4 as uuidv4 } from "uuid";
import GuardrailSelector from "../guardrails/GuardrailSelector";
import NotificationsManager from "../molecules/notifications_manager";
import TagSelector from "../tag_management/TagSelector";
@@ -106,17 +106,10 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
return [];
}
});
- const [selectedModels, setSelectedModels] = useState<string[]>(() => {
- const saved = sessionStorage.getItem("selectedModels");
- try {
- return saved ? JSON.parse(saved) : [];
- } catch (error) {
- console.error("Error parsing selectedModels from sessionStorage", error);
- return [];
- }
- });
+ const [selectedModel, setSelectedModel] = useState<string | undefined>(
+ () => sessionStorage.getItem("selectedModel") || undefined,
+ );
const [showCustomModelInput, setShowCustomModelInput] = useState<boolean>(false);
- const [customModelInput, setCustomModelInput] = useState<string>("");
const [modelInfo, setModelInfo] = useState<ModelGroup[]>([]);
const customModelTimeout = useRef<NodeJS.Timeout | null>(null);
const [endpointType, setEndpointType] = useState<string>(
@@ -220,7 +213,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
selectedGuardrails,
selectedMCPTools,
endpointType,
- selectedModel: selectedModels[0], // Use first model for code snippet
+ selectedModel,
selectedSdk,
selectedVoice,
});
@@ -239,7 +232,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
selectedGuardrails,
selectedMCPTools,
endpointType,
- selectedModels,
+ selectedModel,
]);
useEffect(() => {
@@ -262,7 +255,11 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
sessionStorage.setItem("selectedMCPTools", JSON.stringify(selectedMCPTools));
sessionStorage.setItem("selectedVoice", selectedVoice);
- sessionStorage.setItem("selectedModels", JSON.stringify(selectedModels));
+ if (selectedModel) {
+ sessionStorage.setItem("selectedModel", selectedModel);
+ } else {
+ sessionStorage.removeItem("selectedModel");
+ }
if (messageTraceId) {
sessionStorage.setItem("messageTraceId", messageTraceId);
} else {
@@ -277,7 +274,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
}, [
apiKeySource,
apiKey,
- selectedModels,
+ selectedModel,
endpointType,
selectedTags,
selectedVectorStores,
@@ -286,6 +283,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
responsesSessionId,
useApiSessionManagement,
selectedMCPTools,
+ selectedVoice,
]);
useEffect(() => {
@@ -309,11 +307,11 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
setModelInfo(uniqueModels);
// check for selection overlap or empty model list
+ const hasSelection = uniqueModels.some((m) => m.model_group === selectedModel);
if (!uniqueModels.length) {
- setSelectedModels([]);
- } else if (selectedModels.length === 0) {
- // If no models selected, auto-select the first one
- setSelectedModels([uniqueModels[0].model_group]);
+ setSelectedModel(undefined);
+ } else if (!hasSelection) {
+ setSelectedModel(uniqueModels[0].model_group);
}
} catch (error) {
console.error("Error fetching model info:", error);
@@ -726,8 +724,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
setIsLoading(true);
try {
- if (selectedModels.length > 0) {
- const selectedModel = selectedModels[0]; // For now, use first model (will be updated later for multi-model)
+ if (selectedModel) {
if (endpointType === EndpointType.CHAT) {
// Create chat history for API call - strip out model field and isImage field
// For chat completions, we preserve the multimodal content structure
@@ -935,43 +932,11 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
);
}
- const onModelsChange = (values: string[]) => {
- console.log(`selected models:`, values);
+ const onModelChange = (value: string) => {
+ console.log(`selected ${value}`);
+ setSelectedModel(value);
- // Check if "custom" was added
- if (values.includes("custom")) {
- setShowCustomModelInput(true);
- // Remove "custom" from the actual selection
- setSelectedModels(values.filter((v) => v !== "custom"));
- } else {
- // Limit to 3 models maximum
- if (values.length > 3) {
- NotificationsManager.info("Maximum 3 models can be selected");
- return;
- }
- setSelectedModels(values);
- }
- };
-
- const handleAddCustomModel = () => {
- const trimmedModel = customModelInput.trim();
- if (!trimmedModel) return;
-
- if (selectedModels.includes(trimmedModel)) {
- NotificationsManager.info("Model already selected");
- return;
- }
- if (selectedModels.length >= 3) {
- NotificationsManager.info("Maximum 3 models can be selected");
- return;
- }
- setSelectedModels([...selectedModels, trimmedModel]);
- setCustomModelInput("");
- setShowCustomModelInput(false);
- };
-
- const handleRemoveModel = (modelToRemove: string) => {
- setSelectedModels(selectedModels.filter((m) => m !== modelToRemove));
+ setShowCustomModelInput(value === "custom");
};
const antIcon = <LoadingOutlined style={{ fontSize: 24 }} spin />;
@@ -1015,65 +980,40 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
<div>
<Text className="font-medium block mb-2 text-gray-700 flex items-center">
- <RobotOutlined className="mr-2" /> Select Models
+ <RobotOutlined className="mr-2" /> Select Model
</Text>
<Select
- mode="multiple"
- value={selectedModels}
- placeholder="Select one or more models"
- onChange={onModelsChange}
+ value={selectedModel}
+ placeholder="Select a Model"
+ onChange={onModelChange}
options={[
...Array.from(new Set(modelInfo.map((option) => option.model_group))).map((model_group, index) => ({
value: model_group,
label: model_group,
key: index,
})),
- { value: "custom", label: "+ Add custom model", key: "custom" },
+ { value: "custom", label: "Enter custom model", key: "custom" },
]}
style={{ width: "100%" }}
showSearch={true}
className="rounded-md"
- maxTagCount={0}
- maxTagPlaceholder={`${selectedModels.length} model${selectedModels.length !== 1 ? "s" : ""} selected`}
/>
-
{showCustomModelInput && (
<TextInput
className="mt-2"
- placeholder="Custom Model Name (Enter to add)"
- value={customModelInput}
- onValueChange={setCustomModelInput}
- onKeyDown={(e) => {
- if (e.key === "Enter") {
- handleAddCustomModel();
+ placeholder="Enter custom model name"
+ onValueChange={(value) => {
+ // Using setTimeout to create a simple debounce effect
+ if (customModelTimeout.current) {
+ clearTimeout(customModelTimeout.current);
}
+
+ customModelTimeout.current = setTimeout(() => {
+ setSelectedModel(value);
+ }, 500); // 500ms delay after typing stops
}}
/>
)}
-
- {/* Selected Models Tags */}
- {selectedModels.length > 0 && (
- <div className="mt-2 overflow-hidden">
- <div className="flex flex-wrap gap-1.5">
- {selectedModels.map((model) => (
- <Tag
- key={model}
- closable
- onClose={(e) => {
- e.preventDefault();
- handleRemoveModel(model);
- }}
- color="blue"
- className="px-2 py-0.5 text-xs max-w-[200px]"
- >
- <span className="truncate inline-block max-w-[160px] align-middle" title={model}>
- {model}
- </span>
- </Tag>
- ))}
- </div>
- </div>
- )}
</div>
<div>
@@ -1225,8 +1165,8 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d
{/* Main Chat Area */}
<div className="w-3/4 flex flex-col bg-white">
- <div className="p-4 border-b border-gray-200 flex items-center justify-between">
- <Title className="text-xl font-semibold">Test Key</Title>
+ <div className="p-4 border-b border-gray-200 flex justify-between items-center">
+ <Title className="text-xl font-semibold mb-0">Test Key</Title>
<div className="flex gap-2">
<TremorButton
onClick={clearChatHistory}