mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
working hover
This commit is contained in:
parent
b097edf754
commit
b6d155108e
2 changed files with 82 additions and 12 deletions
76
ui/litellm-dashboard/src/components/top_key_view.tsx
Normal file
76
ui/litellm-dashboard/src/components/top_key_view.tsx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import React, { useState } from "react";
|
||||
import { BarChart } from "@tremor/react";
|
||||
import KeyInfoView from "./key_info_view";
|
||||
import { keyInfoCall } from "./networking";
|
||||
|
||||
interface TopKeyViewProps {
|
||||
topKeys: any[];
|
||||
accessToken: string | null;
|
||||
userID: string | null;
|
||||
userRole: string | null;
|
||||
teams: any[] | null;
|
||||
}
|
||||
|
||||
const TopKeyView: React.FC<TopKeyViewProps> = ({
|
||||
topKeys,
|
||||
accessToken,
|
||||
userID,
|
||||
userRole,
|
||||
teams
|
||||
}) => {
|
||||
const [selectedKey, setSelectedKey] = useState<string | null>(null);
|
||||
const [keyData, setKeyData] = useState<any | undefined>(undefined);
|
||||
|
||||
const handleKeyClick = async (item: any) => {
|
||||
if (!accessToken || !item.key) return;
|
||||
|
||||
try {
|
||||
// Get the full key data using the API key
|
||||
const keyInfo = await keyInfoCall(accessToken, [item.key]);
|
||||
if (keyInfo && keyInfo.keys && keyInfo.keys.length > 0) {
|
||||
setKeyData(keyInfo.keys[0]);
|
||||
setSelectedKey(item.key);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching key info:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setSelectedKey(null);
|
||||
setKeyData(undefined);
|
||||
};
|
||||
|
||||
if (selectedKey && keyData) {
|
||||
return (
|
||||
<KeyInfoView
|
||||
keyId={selectedKey}
|
||||
onClose={handleClose}
|
||||
keyData={keyData}
|
||||
accessToken={accessToken}
|
||||
userID={userID}
|
||||
userRole={userRole}
|
||||
teams={teams}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<BarChart
|
||||
className="mt-4 h-40 cursor-pointer"
|
||||
data={topKeys}
|
||||
index="key"
|
||||
categories={["spend"]}
|
||||
colors={["cyan"]}
|
||||
yAxisWidth={80}
|
||||
tickGap={5}
|
||||
layout="vertical"
|
||||
showXAxis={false}
|
||||
showLegend={false}
|
||||
valueFormatter={(value) => `$${value.toFixed(2)}`}
|
||||
onValueChange={(item) => handleKeyClick(item)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default TopKeyView;
|
||||
|
|
@ -39,6 +39,7 @@ import {
|
|||
getProxyUISettings
|
||||
} from "./networking";
|
||||
import { start } from "repl";
|
||||
import TopKeyView from "./top_key_view";
|
||||
console.log("process.env.NODE_ENV", process.env.NODE_ENV);
|
||||
const isLocal = process.env.NODE_ENV === "development";
|
||||
const proxyBaseUrl = isLocal ? "http://localhost:4000" : null;
|
||||
|
|
@ -656,18 +657,11 @@ const UsagePage: React.FC<UsagePageProps> = ({
|
|||
<Col numColSpan={1}>
|
||||
<Card>
|
||||
<Title>Top API Keys</Title>
|
||||
<BarChart
|
||||
className="mt-4 h-40"
|
||||
data={topKeys}
|
||||
index="key"
|
||||
categories={["spend"]}
|
||||
colors={["cyan"]}
|
||||
yAxisWidth={80}
|
||||
tickGap={5}
|
||||
layout="vertical"
|
||||
showXAxis={false}
|
||||
showLegend={false}
|
||||
valueFormatter={(value) => `$${value.toFixed(2)}`}
|
||||
<TopKeyView
|
||||
topKeys={topKeys}
|
||||
accessToken={accessToken}
|
||||
userID={userID}
|
||||
userRole={userRole}
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue