File size: 1,601 Bytes
e6cfd0f | 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 | import type { DatasetInfo, IterationDetail, Preset } from "./types";
const BASE = "/api/adaevolve";
const PRESETS_BASE = "/api/presets/adaevolve";
async function fetchJson<T>(url: string, opts?: RequestInit): Promise<T> {
const res = await fetch(url, opts);
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.error || `HTTP ${res.status}`);
}
return res.json();
}
// Datasets
export async function loadDataset(repo: string, split = "train"): Promise<DatasetInfo> {
return fetchJson(`${BASE}/datasets/load`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ repo, split }),
});
}
export async function listDatasets(): Promise<DatasetInfo[]> {
return fetchJson(`${BASE}/datasets/`);
}
export async function getIterationDetail(dsId: string, idx: number): Promise<IterationDetail> {
return fetchJson(`${BASE}/datasets/${dsId}/iteration/${idx}`);
}
export async function unloadDataset(dsId: string): Promise<void> {
await fetchJson(`${BASE}/datasets/${dsId}`, { method: "DELETE" });
}
// Presets
export async function listPresets(): Promise<Preset[]> {
return fetchJson(PRESETS_BASE);
}
export async function createPreset(name: string, repo: string, split = "train"): Promise<Preset> {
return fetchJson(PRESETS_BASE, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name, repo, split }),
});
}
export async function deletePreset(id: string): Promise<void> {
await fetchJson(`${PRESETS_BASE}/${id}`, { method: "DELETE" });
}
|