-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathuseBenchmarkCatalog.ts
More file actions
64 lines (58 loc) · 1.5 KB
/
useBenchmarkCatalog.ts
File metadata and controls
64 lines (58 loc) · 1.5 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
import { ref, shallowRef } from 'vue'
import { generateJWT } from '../functions/generate-jwt'
const base = import.meta.env.VITE_API_BASE_URL || '/v1/'
export interface BenchmarkCountry {
id: string
title: string
year: number
chips: number
train: number
validation: number
test: number
license: string
}
export interface ModelRow {
id: string
title: string
description?: string
}
const countries = shallowRef<BenchmarkCountry[]>([])
const models = shallowRef<ModelRow[]>([])
const loading = ref(false)
const error = ref<string | null>(null)
export async function loadBenchmarkCatalog(): Promise<void> {
loading.value = true
error.value = null
try {
const headers = {
Authorization: `Bearer ${generateJWT()}`,
}
const [cRes, mRes] = await Promise.all([
fetch(`${base}benchmarks/countries`, { headers }),
fetch(`${base}models`, { headers }),
])
if (!cRes.ok) {
throw new Error((await cRes.json()).detail || 'Failed to load benchmarks')
}
if (!mRes.ok) {
throw new Error((await mRes.json()).detail || 'Failed to load models')
}
const cJson = await cRes.json()
const mJson = await mRes.json()
countries.value = cJson.countries || []
models.value = mJson.models || []
} catch (e) {
error.value = e instanceof Error ? e.message : String(e)
} finally {
loading.value = false
}
}
export function useBenchmarkCatalog() {
return {
countries,
models,
loading,
error,
loadBenchmarkCatalog,
}
}