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
Revert "[Fix] UI - Revert Changes for Test Key Multiple Model Select (#16372)" (#16386)
Ishaan Jafff1534c16502f
diff --git a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsxindex 6670395aad5..64b6f9c0850 100644--- a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx+++ b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.test.tsx@@ -49,10 +49,55 @@ describe("ChatUI", () => {disabledPersonalKeyCreation={false}/>,);- expect(getByText("Test Key")).toBeInTheDocument();++ await waitFor(() => {+ expect(getByText("Test Key")).toBeInTheDocument();+ });});- it("should show the voice selector when the endpoint type is audio_speech", async () => {+ 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);+ });+ });++ it("should allow users to pick multiple models and render badges for selected models", async () => {const { getByText, container } = render(<ChatUIaccessToken="1234567890"@@ -63,46 +108,66 @@ describe("ChatUI", () => {/>,);- // Wait for the component to renderawait waitFor(() => {expect(getByText("Test Key")).toBeInTheDocument();});- // 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");+ await waitFor(() => {+ expect(getByText("Model 1")).toBeInTheDocument();+ });- expect(selectElement).toBeInTheDocument();+ const selectComponent = container.querySelectorAll(".ant-select-selector")[1];+ expect(selectComponent).toBeTruthy();- // Click on the select to open the dropdown- if (selectElement) {- fireEvent.mouseDown(selectElement);- }+ fireEvent.mouseDown(selectComponent!);- // Wait for the dropdown to appear and find the audio_speech option+ let model2Option: HTMLElement | null = null;await waitFor(() => {- const audioSpeechOption = screen.getByText("/v1/audio/speech");- expect(audioSpeechOption).toBeInTheDocument();+ 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();});- // Click on the audio_speech option- const audioSpeechOption = screen.getByText("/v1/audio/speech");- fireEvent.click(audioSpeechOption);+ fireEvent.click(model2Option!);- // Verify the voice selector appearsawait waitFor(() => {- expect(getByText("Voice")).toBeInTheDocument();+ const model1Badges = screen.getAllByText("Model 1");+ const model2Badges = screen.getAllByText("Model 2");++ expect(model1Badges.length).toBeGreaterThan(0);+ expect(model2Badges.length).toBeGreaterThan(0);});- // Verify the voice select component is present- const voiceText = getByText("Voice");- const voiceSelectContainer = voiceText.parentElement;- const voiceSelectElement = voiceSelectContainer?.querySelector(".ant-select");- expect(voiceSelectElement).toBeInTheDocument();+ fireEvent.mouseDown(selectComponent!);++ let model3Option: HTMLElement | null = null;+ 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();+ });++ 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);});- it("should allow the user to select a model", async () => {+ it("should manage selectedModels state and its side effects", async () => {const { getByText, container } = render(<ChatUIaccessToken="1234567890"@@ -113,7 +178,6 @@ describe("ChatUI", () => {/>,);- // Wait for the component to renderawait waitFor(() => {expect(getByText("Test Key")).toBeInTheDocument();});@@ -122,14 +186,109 @@ 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 renderawait waitFor(() => {- const model1Label = screen.getAllByText("Model 1");- expect(model1Label.length).toBeGreaterThan(0);+ expect(getByText("Test Key")).toBeInTheDocument();});++ // 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.tsxindex 809c7493eb8..f0e8bfb1aff 100644--- a/ui/litellm-dashboard/src/components/chat_ui/ChatUI.tsx+++ b/ui/litellm-dashboard/src/components/chat_ui/ChatUI.tsx@@ -1,3 +1,7 @@+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,@@ -17,13 +21,9 @@ import {ToolOutlined,UserOutlined,} from "@ant-design/icons";-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 { Button, Input, Modal, Select, Spin, Tag, Tooltip, Typography, Upload } from "antd";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,10 +106,17 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dreturn [];}});- const [selectedModel, setSelectedModel] = useState<string | undefined>(- () => sessionStorage.getItem("selectedModel") || undefined,- );+ 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 [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>(@@ -213,7 +220,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dselectedGuardrails,selectedMCPTools,endpointType,- selectedModel,+ selectedModel: selectedModels[0], // Use first model for code snippetselectedSdk,selectedVoice,});@@ -232,7 +239,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dselectedGuardrails,selectedMCPTools,endpointType,- selectedModel,+ selectedModels,]);useEffect(() => {@@ -255,11 +262,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dsessionStorage.setItem("selectedMCPTools", JSON.stringify(selectedMCPTools));sessionStorage.setItem("selectedVoice", selectedVoice);- if (selectedModel) {- sessionStorage.setItem("selectedModel", selectedModel);- } else {- sessionStorage.removeItem("selectedModel");- }+ sessionStorage.setItem("selectedModels", JSON.stringify(selectedModels));if (messageTraceId) {sessionStorage.setItem("messageTraceId", messageTraceId);} else {@@ -274,7 +277,7 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d}, [apiKeySource,apiKey,- selectedModel,+ selectedModels,endpointType,selectedTags,selectedVectorStores,@@ -283,7 +286,6 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dresponsesSessionId,useApiSessionManagement,selectedMCPTools,- selectedVoice,]);useEffect(() => {@@ -307,11 +309,11 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dsetModelInfo(uniqueModels);// check for selection overlap or empty model list- const hasSelection = uniqueModels.some((m) => m.model_group === selectedModel);if (!uniqueModels.length) {- setSelectedModel(undefined);- } else if (!hasSelection) {- setSelectedModel(uniqueModels[0].model_group);+ setSelectedModels([]);+ } else if (selectedModels.length === 0) {+ // If no models selected, auto-select the first one+ setSelectedModels([uniqueModels[0].model_group]);}} catch (error) {console.error("Error fetching model info:", error);@@ -724,7 +726,8 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, dsetIsLoading(true);try {- if (selectedModel) {+ if (selectedModels.length > 0) {+ const selectedModel = selectedModels[0]; // For now, use first model (will be updated later for multi-model)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@@ -932,11 +935,43 @@ const ChatUI: React.FC<ChatUIProps> = ({ accessToken, token, userRole, userID, d);}- const onModelChange = (value: string) => {- console.log(`selected ${value}`);- setSelectedModel(value);+ const onModelsChange = (values: string[]) => {+ console.log(`selected models:`, values);- setShowCustomModelInput(value === "custom");+ // 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));};const antIcon = <LoadingOutlined style={{ fontSize: 24 }} spin />;@@ -980,40 +1015,65 @@ 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 Model+ <RobotOutlined className="mr-2" /> Select Models</Text><Select- value={selectedModel}- placeholder="Select a Model"- onChange={onModelChange}+ mode="multiple"+ value={selectedModels}+ placeholder="Select one or more models"+ onChange={onModelsChange}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: "Enter custom model", key: "custom" },+ { value: "custom", label: "+ Add custom model", key: "custom" },]}style={{ width: "100%" }}showSearch={true}className="rounded-md"+ maxTagCount={0}+ maxTagPlaceholder={`${selectedModels.length} model${selectedModels.length !== 1 ? "s" : ""} selected`}/>+{showCustomModelInput && (<TextInputclassName="mt-2"- placeholder="Enter custom model name"- onValueChange={(value) => {- // Using setTimeout to create a simple debounce effect- if (customModelTimeout.current) {- clearTimeout(customModelTimeout.current);+ placeholder="Custom Model Name (Enter to add)"+ value={customModelInput}+ onValueChange={setCustomModelInput}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ handleAddCustomModel();}-- 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>@@ -1165,8 +1225,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 justify-between items-center">- <Title className="text-xl font-semibold mb-0">Test Key</Title>+ <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="flex gap-2"><TremorButtononClick={clearChatHistory}