From 72d7b268116a99eaf2028a501f2706a84b0d644e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 3 Apr 2025 21:00:42 -0700 Subject: [PATCH] fix allow selecting endpoint on test key page --- .../src/components/chat_ui.tsx | 50 ++++++++++------ .../chat_ui/llm_calls/fetch_models.tsx | 59 +++++++------------ 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/ui/litellm-dashboard/src/components/chat_ui.tsx b/ui/litellm-dashboard/src/components/chat_ui.tsx index 547e926559b..bf483a790e2 100644 --- a/ui/litellm-dashboard/src/components/chat_ui.tsx +++ b/ui/litellm-dashboard/src/components/chat_ui.tsx @@ -25,7 +25,8 @@ import { import { message, Select } from "antd"; import { makeOpenAIChatCompletionRequest } from "./chat_ui/llm_calls/chat_completion"; import { makeOpenAIImageGenerationRequest } from "./chat_ui/llm_calls/image_generation"; -import { fetchAvailableModels } from "./chat_ui/llm_calls/fetch_models"; +import { fetchAvailableModels, ModelGroup } from "./chat_ui/llm_calls/fetch_models"; +import { litellmModeMapping, ModelMode, EndpointType } from "./chat_ui/mode_endpoint_mapping"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { Typography } from "antd"; import { coy } from 'react-syntax-highlighter/dist/esm/styles/prism'; @@ -55,7 +56,7 @@ const ChatUI: React.FC = ({ undefined ); const [showCustomModelInput, setShowCustomModelInput] = useState(false); - const [modelInfo, setModelInfo] = useState([]); + const [modelInfo, setModelInfo] = useState([]); const customModelTimeout = useRef(null); const [endpointType, setEndpointType] = useState<'chat' | 'image'>('chat'); @@ -74,15 +75,18 @@ const ChatUI: React.FC = ({ try { const uniqueModels = await fetchAvailableModels( useApiKey, - userID, - userRole ); console.log("Fetched models:", uniqueModels); if (uniqueModels.length > 0) { setModelInfo(uniqueModels); - setSelectedModel(uniqueModels[0].value); + setSelectedModel(uniqueModels[0].model_group); + // Auto-set endpoint based on the first model's mode if available + const firstMode = uniqueModels[0].mode as ModelMode; + if (firstMode && litellmModeMapping[firstMode]) { + setEndpointType(litellmModeMapping[firstMode] as EndpointType); + } } } catch (error) { console.error("Error fetching model info:", error); @@ -202,6 +206,14 @@ const ChatUI: React.FC = ({ const onModelChange = (value: string) => { console.log(`selected ${value}`); setSelectedModel(value); + // Look up the selected model to auto-select the endpoint type + const selectedOption = modelInfo.find((option) => option.model_group === value); + if (selectedOption && selectedOption.mode) { + const mode = selectedOption.mode as ModelMode; + if (litellmModeMapping[mode]) { + setEndpointType(litellmModeMapping[mode] as EndpointType); + } + } setShowCustomModelInput(value === 'custom'); }; @@ -245,23 +257,15 @@ const ChatUI: React.FC = ({ )} - Endpoint Type: - ({ + value: option.model_group, + label: option.model_group + })), { value: 'custom', label: 'Enter custom model' } ]} style={{ width: "350px" }} @@ -283,7 +287,19 @@ const ChatUI: React.FC = ({ }} /> )} + Endpoint Type: +