diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index 5f509c5ba..ec0945e0b 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -818,6 +818,41 @@ export const teamCreateCall = async ( }; +export const keyUpdateCall = async ( + accessToken: string, + formValues: Record // Assuming formValues is an object +) => { + try { + console.log("Form Values in keyUpdateCall:", formValues); // Log the form values before making the API call + + const url = proxyBaseUrl ? `${proxyBaseUrl}/key/update` : `/key/update`; + const response = await fetch(url, { + method: "POST", + headers: { + Authorization: `Bearer ${accessToken}`, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + ...formValues, // Include formValues in the request body + }), + }); + + if (!response.ok) { + const errorData = await response.text(); + message.error("Failed to update key: " + errorData); + console.error("Error response from the server:", errorData); + throw new Error("Network response was not ok"); + } + const data = await response.json(); + console.log("Update key Response:", data); + return data; + // Handle success - you might want to update some state or UI based on the created key + } catch (error) { + console.error("Failed to create key:", error); + throw error; + } +}; + export const teamUpdateCall = async ( accessToken: string, formValues: Record // Assuming formValues is an object diff --git a/ui/litellm-dashboard/src/components/user_dashboard.tsx b/ui/litellm-dashboard/src/components/user_dashboard.tsx index 2161a5e56..8f9977e08 100644 --- a/ui/litellm-dashboard/src/components/user_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/user_dashboard.tsx @@ -220,6 +220,7 @@ const UserDashboard: React.FC = ({ accessToken={accessToken} selectedTeam={selectedTeam ? selectedTeam : null} data={keys} + userModels={userModels} setData={setKeys} /> void; @@ -46,6 +49,7 @@ interface ViewKeyTableProps { userID: string; accessToken: string; selectedTeam: any | null; + userModels: string[]; data: any[] | null; setData: React.Dispatch>; } @@ -70,6 +74,7 @@ const ViewKeyTable: React.FC = ({ userID, accessToken, selectedTeam, + userModels, data, setData, }) => { @@ -88,7 +93,22 @@ const ViewKeyTable: React.FC = ({ const EditKeyModal: React.FC = ({ visible, onCancel, token, onSubmit }) => { const [form] = Form.useForm(); - console.log("in edit modal, token:", token); + + // check token.models length == 0 + if (token.models.length == 0 && selectedTeam) { + token.models = selectedTeam.models; + + } + + const handleModelSelection = (selectedModels: string[]) => { + if (selectedModels.includes("all_models")) { + // Select all models except "All Models" + const allModelsExceptAll = selectedTeam ? selectedTeam.models : userModels; + form.setFieldsValue({ + models: allModelsExceptAll + }); + } + }; const handleOk = () => { form @@ -135,26 +155,54 @@ const ViewKeyTable: React.FC = ({ mode="multiple" placeholder="Select models" style={{ width: "100%" }} - // onChange={(selectedModels) => handleModelSelection(selectedModels)} + onChange={(selectedModels) => handleModelSelection(selectedModels)} > - {/* - */} + {selectedTeam && selectedTeam.models ? ( + selectedTeam.models.map((model: string) => ( + + )) + ) : ( + userModels.map((model: string) => ( + + )) + )} + - - - - - - - + { + if (value && selectedTeam && selectedTeam.max_budget !== null && value > selectedTeam.max_budget) { + throw new Error(`Budget cannot exceed team max budget: $${selectedTeam.max_budget}`); + } + }, + }, + ]} + > + + +
- Create Key + Edit Key
@@ -176,26 +224,28 @@ const handleEditCancel = () => { const handleEditSubmit = async (formValues: Record) => { // Call API to update team with teamId and values - // const teamId = formValues.team_id; // get team_id - - console.log("handleEditSubmit:", formValues); if (accessToken == null) { return; } + const currentKey = formValues.token; + formValues.key = currentKey; + + console.log("handleEditSubmit:", formValues); - // let newTeamValues = await teamUpdateCall(accessToken, formValues); + let newKeyValues = await keyUpdateCall(accessToken, formValues); + console.log("handleEditSubmit: newKeyValues", newKeyValues); - // // Update the teams state with the updated team data - // if (teams) { - // const updatedTeams = teams.map((team) => - // team.team_id === teamId ? newTeamValues.data : team - // ); - // setTeams(updatedTeams); - // } - // message.success("Team updated successfully"); + // Update the keys with the update key + if (data) { + const updatedData = data.map((key) => + key.token === currentKey ? newKeyValues : key + ); + setData(updatedData); + } + message.success("Key updated successfully"); - // setEditModalVisible(false); - // setSelectedTeam(null); + setEditModalVisible(false); + setSelectedToken(null); };