From 84652a82cbf1f515feec13918587fb0935749d07 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 19 Feb 2024 21:23:59 -0800 Subject: [PATCH 1/2] (feat) adin ui show all pending user requests --- .../src/components/model_dashboard.tsx | 42 ++++++++++++++++++- .../src/components/networking.tsx | 29 +++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx index dbd5c7c94d..0696ca6ba3 100644 --- a/ui/litellm-dashboard/src/components/model_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from "react"; import { Card, Title, Subtitle, Table, TableHead, TableRow, TableCell, TableBody, Metric, Grid } from "@tremor/react"; -import { modelInfoCall } from "./networking"; +import { modelInfoCall, userGetRequesedtModelsCall } from "./networking"; import { Badge, BadgeDelta, Button } from '@tremor/react'; import RequestAccess from "./request_model_access"; @@ -18,6 +18,8 @@ const ModelDashboard: React.FC = ({ userID, }) => { const [modelData, setModelData] = useState({ data: [] }); + const [pendingRequests, setPendingRequests] = useState([]); + useEffect(() => { if (!accessToken || !token || !userRole || !userID) { @@ -29,6 +31,14 @@ const ModelDashboard: React.FC = ({ const modelDataResponse = await modelInfoCall(accessToken, userID, userRole); console.log("Model data response:", modelDataResponse.data); setModelData(modelDataResponse); + + // if userRole is Admin, show the pending requests + if (userRole === "Admin" && accessToken) { + const user_requests = await userGetRequesedtModelsCall(accessToken); + console.log("Pending Requests:", pendingRequests); + setPendingRequests(user_requests.requests || []); + } + } catch (error) { console.error("There was an error fetching the model data", error); } @@ -91,6 +101,7 @@ const ModelDashboard: React.FC = ({ } // when users click request access show pop up to allow them to request access + return (
@@ -127,6 +138,35 @@ const ModelDashboard: React.FC = ({ + { + userRole === "Admin" && pendingRequests ? ( + + + + Pending Requests + + User ID + Requested Models + Justification + Justification + + + + {pendingRequests.map((request: any) => ( + +

{request.user_id}

+

{request.models[0]}

+

{request.justification}

+

{request.user_id}

+ + +
+ ))} +
+
+
+ ) : null + }
); diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx index ccdc279d23..34368c8bc1 100644 --- a/ui/litellm-dashboard/src/components/networking.tsx +++ b/ui/litellm-dashboard/src/components/networking.tsx @@ -326,4 +326,33 @@ export const userRequestModelCall = async (accessToken: String, model: String, U console.error("Failed to create key:", error); throw error; } +}; + + +export const userGetRequesedtModelsCall = async (accessToken: String) => { + try { + const url = proxyBaseUrl ? `${proxyBaseUrl}/user/get_requests` : `user/get_requests`; + console.log("in userGetRequesedtModelsCall:", url); + const response = await fetch(url, { + method: "GET", + headers: { + Authorization: `Bearer ${accessToken}`, + "Content-Type": "application/json", + }, + }); + + if (!response.ok) { + const errorData = await response.text(); + message.error("Failed to delete key: " + errorData); + throw new Error("Network response was not ok"); + } + const data = await response.json(); + console.log(data); + message.success(""); + return data; + // Handle success - you might want to update some state or UI based on the created key + } catch (error) { + console.error("Failed to get requested models:", error); + throw error; + } }; \ No newline at end of file From 9683760241ca5849ce5861c427156527b98fc8c1 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Mon, 19 Feb 2024 21:35:28 -0800 Subject: [PATCH 2/2] (ui) show pendingRequests --- ui/litellm-dashboard/src/components/model_dashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx index 0696ca6ba3..edf13cf2e4 100644 --- a/ui/litellm-dashboard/src/components/model_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx @@ -139,7 +139,7 @@ const ModelDashboard: React.FC = ({ { - userRole === "Admin" && pendingRequests ? ( + userRole === "Admin" && pendingRequests && pendingRequests.length > 0 ? (