| | 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(); |
| | } |
| |
|
| | |
| | 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" }); |
| | } |
| |
|
| | |
| | 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" }); |
| | } |
| |
|