-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.astro
More file actions
93 lines (85 loc) · 3.06 KB
/
index.astro
File metadata and controls
93 lines (85 loc) · 3.06 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
---
import PageLayout from "@layouts/PageLayout.astro";
import Container from "@components/Container.astro";
import ArenaRankings from "@components/ArenaRankings.svelte";
export const prerender = false;
let tokenData = {};
let error = null;
try {
const response = await fetch(`${process.env.VITE_API_URL || 'https://api.swissai.svc.cscs.ch'}/v1/metrics`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
view: "observations",
metrics: [{ measure: "totalTokens", aggregation: "sum" }],
dimensions: [{ field: "providedModelName" }],
filters: [],
fromTimestamp: "2025-12-01T00:00:00Z",
toTimestamp: "2025-12-16T00:00:00Z",
}),
});
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
const result = await response.json();
// Transform API response to expected format
// API returns { data: [ { providedModelName: "...", sum_totalTokens: "..." } ] }
if (result.data && Array.isArray(result.data)) {
tokenData = result.data.reduce(
(acc: Record<string, number>, item: any) => {
if (item.providedModelName) {
// Parse the token count as an integer
acc[item.providedModelName] = parseInt(
item.sum_totalTokens || "0",
10,
);
}
return acc;
},
{},
);
}
} catch (e: any) {
console.error("Failed to fetch metrics:", e);
error = e.message;
}
---
<PageLayout title="Leaderboard" description="Model rankings based on usage">
<Container>
<div class="space-y-10">
<div class="text-center space-y-4">
<h1
class="text-4xl font-bold tracking-tight text-slate-900 dark:text-white sm:text-5xl"
>
Leaderboard
</h1>
<p
class="mx-auto max-w-2xl text-lg text-slate-600 dark:text-slate-400"
>
Discover the top-performing models based on total token
usage.
</p>
</div>
<div class="card p-1">
<div class="p-6 bg-white dark:bg-slate-900 rounded-xl">
{
error ? (
<div class="text-center text-red-500 py-4">
Error loading data: {error}
</div>
) : (
<ArenaRankings
client:load
elosData={tokenData}
metricLabel="Total Tokens"
enableDateFilter={true}
/>
)
}
</div>
</div>
</div>
</Container>
</PageLayout>