From db2a55a3d232c84826bbe70aebb2bf500ee4f365 Mon Sep 17 00:00:00 2001 From: tanjiro <56165694+NANDINI-star@users.noreply.github.com> Date: Sat, 28 Jun 2025 10:18:56 +0900 Subject: [PATCH] Add "Get Code" Feature (#11629) * added get code * modify template * fixed code template * put the codesnippets in a different file * minor --- .../src/components/chat_ui.tsx | 114 ++++- .../src/components/chat_ui/CodeSnippets.tsx | 432 ++++++++++++++++++ 2 files changed, 528 insertions(+), 18 deletions(-) create mode 100644 ui/litellm-dashboard/src/components/chat_ui/CodeSnippets.tsx diff --git a/ui/litellm-dashboard/src/components/chat_ui.tsx b/ui/litellm-dashboard/src/components/chat_ui.tsx index 673924a0e5..582735a3e6 100644 --- a/ui/litellm-dashboard/src/components/chat_ui.tsx +++ b/ui/litellm-dashboard/src/components/chat_ui.tsx @@ -19,12 +19,12 @@ import { Text, SelectItem, TextInput, - Button, + Button as TremorButton, Divider, } from "@tremor/react"; import { v4 as uuidv4 } from 'uuid'; -import { message, Select, Spin, Typography, Tooltip, Input, Upload } from "antd"; +import { message, Select, Spin, Typography, Tooltip, Input, Upload, Modal, Button } from "antd"; import { makeOpenAIChatCompletionRequest } from "./chat_ui/llm_calls/chat_completion"; import { makeOpenAIImageGenerationRequest } from "./chat_ui/llm_calls/image_generation"; import { makeOpenAIImageEditsRequest } from "./chat_ui/llm_calls/image_edits"; @@ -39,6 +39,7 @@ import TagSelector from "./tag_management/TagSelector"; import VectorStoreSelector from "./vector_store_management/VectorStoreSelector"; import GuardrailSelector from "./guardrails/GuardrailSelector"; import { determineEndpointType } from "./chat_ui/EndpointUtils"; +import { generateCodeSnippet } from "./chat_ui/CodeSnippets"; import { MessageType } from "./chat_ui/types"; import ReasoningContent from "./chat_ui/ReasoningContent"; import ResponseMetrics, { TokenUsage } from "./chat_ui/ResponseMetrics"; @@ -56,7 +57,8 @@ import { InfoCircleOutlined, SafetyOutlined, UploadOutlined, - PictureOutlined + PictureOutlined, + CodeOutlined } from "@ant-design/icons"; const { TextArea } = Input; @@ -98,9 +100,31 @@ const ChatUI: React.FC = ({ const [messageTraceId, setMessageTraceId] = useState(null); const [uploadedImage, setUploadedImage] = useState(null); const [imagePreviewUrl, setImagePreviewUrl] = useState(null); + const [isGetCodeModalVisible, setIsGetCodeModalVisible] = useState(false); + const [generatedCode, setGeneratedCode] = useState(""); + const [selectedSdk, setSelectedSdk] = useState<'openai' | 'azure'>('openai'); const chatEndRef = useRef(null); + useEffect(() => { + if (isGetCodeModalVisible) { + const code = generateCodeSnippet({ + apiKeySource, + accessToken, + apiKey, + inputMessage, + chatHistory, + selectedTags, + selectedVectorStores, + selectedGuardrails, + endpointType, + selectedModel, + selectedSdk, + }); + setGeneratedCode(code); + } + }, [isGetCodeModalVisible, selectedSdk, apiKeySource, accessToken, apiKey, inputMessage, chatHistory, selectedTags, selectedVectorStores, selectedGuardrails, endpointType, selectedModel]); + useEffect(() => { let userApiKey = apiKeySource === 'session' ? accessToken : apiKey; if (!userApiKey || !token || !userRole || !userID) { @@ -472,10 +496,10 @@ const ChatUI: React.FC = ({ return (
-
+
{/* Left Sidebar with Controls */} -
-
+
+ Configurations
@@ -607,19 +631,30 @@ const ChatUI: React.FC = ({ />
- +
+ + Clear Chat + +
-
{/* Main Chat Area */}
+
+ Test Key + setIsGetCodeModalVisible(true)} + className="bg-gray-100 hover:bg-gray-200 text-gray-700 border-gray-300" + icon={CodeOutlined} + > + Get Code + +
{chatHistory.length === 0 && (
@@ -781,15 +816,15 @@ const ChatUI: React.FC = ({ style={{ resize: 'none', paddingRight: '10px', paddingLeft: '10px' }} /> {isLoading ? ( - + ) : ( - + )}
+ setIsGetCodeModalVisible(false)} + footer={null} + width={800} + > +
+
+ SDK Type +