diff --git a/ui/litellm-dashboard/src/components/create_key_button.tsx b/ui/litellm-dashboard/src/components/create_key_button.tsx index d0b0c20307c..a76b3b1e390 100644 --- a/ui/litellm-dashboard/src/components/create_key_button.tsx +++ b/ui/litellm-dashboard/src/components/create_key_button.tsx @@ -1,11 +1,14 @@ + "use client"; import React, { useState, useEffect, useRef } from "react"; import { Button, TextInput, Grid, Col } from "@tremor/react"; -import { message } from "antd"; import { Card, Metric, Text } from "@tremor/react"; +import { Button as Button2, Modal, Form, Input, InputNumber, Select, message } from "antd"; import { keyCreateCall } from "./networking"; -// Define the props type + +const { Option } = Select; + interface CreateKeyProps { userID: string; accessToken: string; @@ -14,8 +17,6 @@ interface CreateKeyProps { setData: React.Dispatch>; } -import { Modal, Button as Button2 } from "antd"; - const CreateKey: React.FC = ({ userID, accessToken, @@ -23,51 +24,108 @@ const CreateKey: React.FC = ({ data, setData, }) => { + const [form] = Form.useForm(); const [isModalVisible, setIsModalVisible] = useState(false); const [apiKey, setApiKey] = useState(null); + const handleOk = () => { - // Handle the OK action - console.log("OK Clicked"); setIsModalVisible(false); + form.resetFields(); }; const handleCancel = () => { - // Handle the cancel action or closing the modal - console.log("Modal closed"); setIsModalVisible(false); setApiKey(null); + form.resetFields(); }; - const handleCreate = async () => { - if (data == null) { - return; - } + const handleCreate = async (formValues: Record) => { try { message.info("Making API Call"); + // Check if "models" exists and is not an empty string + if (formValues.models && formValues.models.trim() !== '') { + // Format the "models" field as an array + formValues.models = formValues.models.split(',').map((model: string) => model.trim()); + } else { + // If "models" is undefined or an empty string, set it to an empty array + formValues.models = []; + } setIsModalVisible(true); - const response = await keyCreateCall(proxyBaseUrl, accessToken, userID); - // Successfully completed the deletion. Update the state to trigger a rerender. - setData([...data, response]); + const response = await keyCreateCall(proxyBaseUrl, accessToken, userID, formValues); + setData((prevData) => (prevData ? [...prevData, response] : [response])); // Check if prevData is null setApiKey(response["key"]); message.success("API Key Created"); + form.resetFields(); } catch (error) { - console.error("Error deleting the key:", error); - // Handle any error situations, such as displaying an error message to the user. + console.error("Error creating the key:", error); } }; + return (
- - +
+ + + + + + + + + + + + + + + + + + + +
+ + Create Key + +
+
+
+ {apiKey && ( + +

Please save this secret key somewhere safe and accessible. For @@ -84,7 +142,8 @@ const CreateKey: React.FC = ({ )} - + + )}

); }; diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index b0a0ede62f1..92170accedb 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -3,11 +3,13 @@ */ export const keyCreateCall = async ( - proxyBaseUrl: String, - accessToken: String, - userID: String + proxyBaseUrl: string, + accessToken: string, + userID: string, + formValues: Record // Assuming formValues is an object ) => { try { + console.log("Form Values in keyCreateCall:", formValues); // Log the form values before making the API call const response = await fetch(`${proxyBaseUrl}/key/generate`, { method: "POST", headers: { @@ -16,15 +18,18 @@ export const keyCreateCall = async ( }, body: JSON.stringify({ user_id: userID, + ...formValues, // Include formValues in the request body }), }); if (!response.ok) { + const errorData = await response.json(); + console.error("Error response from the server:", errorData); throw new Error("Network response was not ok"); } const data = await response.json(); - console.log(data); + console.log("API Response:", data); return data; // Handle success - you might want to update some state or UI based on the created key } catch (error) { @@ -33,6 +38,7 @@ export const keyCreateCall = async ( } }; + export const keyDeleteCall = async ( proxyBaseUrl: String, accessToken: String,