-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathLLMUsageTable.jsx
More file actions
256 lines (239 loc) · 5.91 KB
/
LLMUsageTable.jsx
File metadata and controls
256 lines (239 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import {
CheckCircleOutlined,
CloseCircleOutlined,
InfoCircleOutlined,
} from "@ant-design/icons";
import {
Alert,
Card,
Empty,
Spin,
Table,
Tabs,
Tag,
Tooltip,
Typography,
} from "antd";
import PropTypes from "prop-types";
import { useEffect, useState } from "react";
import { ApiDeployments, ETLIcon, Task, Workflows } from "../../assets/index";
import { useDeploymentUsage } from "../../hooks/useMetricsData";
import "./MetricsDashboard.css";
const { Text } = Typography;
const columns = [
{
title: "Deployment",
dataIndex: "deployment_name",
key: "deployment_name",
ellipsis: true,
render: (text) => <Text strong>{text}</Text>,
},
{
title: (
<span>
Tokens{" "}
<Tooltip title="Total LLM tokens consumed by this deployment">
<InfoCircleOutlined className="llm-usage-info-icon" />
</Tooltip>
</span>
),
dataIndex: "total_tokens",
key: "total_tokens",
sorter: (a, b) => a.total_tokens - b.total_tokens,
defaultSortOrder: "descend",
render: (value) => (value || 0).toLocaleString(),
width: 130,
},
{
title: "LLM Calls",
dataIndex: "call_count",
key: "call_count",
sorter: (a, b) => a.call_count - b.call_count,
render: (value) => (value || 0).toLocaleString(),
width: 100,
},
{
title: "Executions",
dataIndex: "execution_count",
key: "execution_count",
sorter: (a, b) => a.execution_count - b.execution_count,
render: (_, record) => {
const total = record.execution_count || 0;
const completed = record.completed_executions || 0;
const failed = record.failed_executions || 0;
return (
<span>
{total.toLocaleString()}{" "}
{completed > 0 && (
<Tooltip title={`${completed} completed`}>
<Tag color="success" className="llm-usage-tag-compact">
<CheckCircleOutlined /> {completed}
</Tag>
</Tooltip>
)}
{failed > 0 && (
<Tooltip title={`${failed} failed`}>
<Tag color="error">
<CloseCircleOutlined /> {failed}
</Tag>
</Tooltip>
)}
</span>
);
},
width: 180,
},
{
title: "Pages",
dataIndex: "total_pages_processed",
key: "total_pages_processed",
sorter: (a, b) =>
(a.total_pages_processed || 0) - (b.total_pages_processed || 0),
render: (value) => (value || 0).toLocaleString(),
width: 100,
},
{
title: "Cost",
dataIndex: "total_cost",
key: "total_cost",
sorter: (a, b) => a.total_cost - b.total_cost,
render: (value) => `$${(value || 0).toFixed(4)}`,
width: 110,
},
{
title: "Last Run",
dataIndex: "last_execution_at",
key: "last_execution_at",
sorter: (a, b) =>
(a.last_execution_at || "").localeCompare(b.last_execution_at || ""),
render: (value) => (value ? value.split("T")[0] : "-"),
width: 110,
},
];
function DeploymentUsageTable({ startDate, endDate, refetchRef }) {
const [activeType, setActiveType] = useState("API");
const { data, loading, error, refetch } = useDeploymentUsage(
activeType,
startDate,
endDate,
);
// Expose refetch to parent via ref
useEffect(() => {
if (refetchRef) {
refetchRef.current = refetch;
}
return () => {
if (refetchRef) {
refetchRef.current = null;
}
};
}, [refetch, refetchRef]);
const handleTabChange = (key) => {
setActiveType(key);
};
const deploymentTabs = [
{
key: "API",
label: "API Deployments",
icon: (
<ApiDeployments
className={`log-tab-icon ${activeType === "API" ? "active" : ""}`}
/>
),
},
{
key: "ETL",
label: "ETL Pipelines",
icon: (
<ETLIcon
className={`log-tab-icon ${activeType === "ETL" ? "active" : ""}`}
/>
),
},
{
key: "TASK",
label: "Task Pipelines",
icon: (
<Task
className={`log-tab-icon ${activeType === "TASK" ? "active" : ""}`}
/>
),
},
{
key: "WF",
label: "Workflows",
icon: (
<Workflows
className={`log-tab-icon ${activeType === "WF" ? "active" : ""}`}
/>
),
},
];
const renderContent = () => {
if (loading) {
return (
<div className="metrics-loading">
<Spin />
</div>
);
}
if (error) {
return (
<Alert
message="Failed to load usage data"
description={error}
type="error"
showIcon
className="llm-usage-error-alert"
/>
);
}
if (!data?.deployments?.length) {
return <Empty description="No LLM usage data for this period" />;
}
return (
<Table
dataSource={data.deployments}
columns={columns}
rowKey="deployment_id"
size="middle"
pagination={false}
scroll={{ x: 900, y: 400 }}
className="llm-usage-table"
/>
);
};
return (
<Card className="metrics-chart-card llm-usage-card">
<div className="llm-usage-header">
<Text strong className="llm-usage-title">
Usage by Deployment
</Text>
</div>
<Tabs
items={deploymentTabs}
activeKey={activeType}
onChange={handleTabChange}
size="small"
className="deployment-type-tabs"
/>
{data?.range_truncated && (
<Text type="secondary" className="llm-usage-subtitle">
Date range was limited to the last 30 days
</Text>
)}
{renderContent()}
</Card>
);
}
DeploymentUsageTable.propTypes = {
startDate: PropTypes.string,
endDate: PropTypes.string,
refetchRef: PropTypes.shape({ current: PropTypes.func }),
};
DeploymentUsageTable.defaultProps = {
startDate: null,
endDate: null,
refetchRef: null,
};
export { DeploymentUsageTable };