From 7bfd02350aebe2edabdadb875d6ba61421b7958b Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 8 May 2024 10:38:27 -0700 Subject: [PATCH] stash - users usage tab --- ui/litellm-dashboard/src/components/usage.tsx | 53 ++++++++++++++++++- .../src/components/view_users.tsx | 11 ++-- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/ui/litellm-dashboard/src/components/usage.tsx b/ui/litellm-dashboard/src/components/usage.tsx index 07ca8ed14..1bd8838b6 100644 --- a/ui/litellm-dashboard/src/components/usage.tsx +++ b/ui/litellm-dashboard/src/components/usage.tsx @@ -3,13 +3,14 @@ import { BarChart, BarList, Card, Title, Table, TableHead, TableHeaderCell, Tabl import React, { useState, useEffect } from "react"; import ViewUserSpend from "./view_user_spend"; -import { Grid, Col, Text, LineChart, TabPanel, TabPanels, TabGroup, TabList, Tab, Select, SelectItem } from "@tremor/react"; +import { Grid, Col, Text, LineChart, TabPanel, TabPanels, TabGroup, TabList, Tab, Select, SelectItem, DateRangePicker, DateRangePickerValue } from "@tremor/react"; import { userSpendLogsCall, keyInfoCall, adminSpendLogsCall, adminTopKeysCall, adminTopModelsCall, + adminTopEndUsersCall, teamSpendLogsCall, tagsSpendLogsCall, modelMetricsCall, @@ -112,6 +113,10 @@ const UsagePage: React.FC = ({ const [topTagsData, setTopTagsData] = useState([]); const [uniqueTeamIds, setUniqueTeamIds] = useState([]); const [totalSpendPerTeam, setTotalSpendPerTeam] = useState([]); + const [dateValue, setDateValue] = useState({ + from: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), + to: new Date(), + }); const firstDay = new Date( currentDate.getFullYear(), @@ -127,6 +132,10 @@ const UsagePage: React.FC = ({ let startTime = formatDate(firstDay); let endTime = formatDate(lastDay); + // const updateEndUserUsage(startTime: string, endTime: string) { + + // } + function formatDate(date: Date) { const year = date.getFullYear(); let month = date.getMonth() + 1; // JS month index starts from 0 @@ -193,6 +202,12 @@ const UsagePage: React.FC = ({ const top_tags = await tagsSpendLogsCall(accessToken); setTopTagsData(top_tags.top_10_tags); + // get spend per end-user + let spend_user_call = await adminTopEndUsersCall(accessToken, null); + setTopUsers(spend_user_call); + + console.log("spend/user result", spend_user_call); + } else if (userRole == "App Owner") { await userSpendLogsCall( accessToken, @@ -224,7 +239,6 @@ const UsagePage: React.FC = ({ spend: k["spend"], })); setTopKeys(filtered_keys); - setTopUsers(getTopUsers(response)); setKeySpendData(response); } }); @@ -342,7 +356,42 @@ const UsagePage: React.FC = ({ + { + setDateValue(value); + updateModelMetrics(selectedModelGroup, value.from, value.to); // Call updateModelMetrics with the new date range + }} + /> + End Users of your LLM API calls. Tracked When a `user` param is passed in your LLM calls + + + + + + + + End User + Spend + Total Events + + + + + {topUsers?.map((user: any, index: number) => ( + + {user.end_user} + {user.total_spend?.toFixed(4)} + {user.total_events} + + ))} + +
+ +
+
diff --git a/ui/litellm-dashboard/src/components/view_users.tsx b/ui/litellm-dashboard/src/components/view_users.tsx index b3960965c..fd152f25f 100644 --- a/ui/litellm-dashboard/src/components/view_users.tsx +++ b/ui/litellm-dashboard/src/components/view_users.tsx @@ -158,12 +158,11 @@ const ViewUserDashboard: React.FC = ({
Key Owners: Users on LiteLLM that created API Keys. Automatically tracked by LiteLLM - End Users: End Users of your LLM API calls. Tracked When a `user` param is passed in your LLM calls +
Key Owners - End-Users @@ -220,7 +219,7 @@ const ViewUserDashboard: React.FC = ({
- Key + {/* Key + */}
- + {/*
End User @@ -260,7 +259,7 @@ const ViewUserDashboard: React.FC = ({ ))} -
+ */}