Zayne Rea Sprague
new tab
b630916
const BASE = "/api/rlm-eval";
async function fetchJson<T>(url: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${BASE}${url}`, {
headers: { "Content-Type": "application/json" },
...init,
});
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.error || `HTTP ${res.status}`);
}
return res.json();
}
const PRESETS_BASE = "/api/presets/rlm-eval";
async function fetchPresetsJson<T>(url: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${PRESETS_BASE}${url}`, {
headers: { "Content-Type": "application/json" }, ...init,
});
if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `HTTP ${res.status}`); }
return res.json();
}
export const api = {
loadDataset: (repo: string, config?: string, split?: string) =>
fetchJson<{
id: string;
repo: string;
name: string;
config: string;
split: string;
metadata: Record<string, unknown>;
n_examples: number;
n_rows: number;
}>("/datasets/load", {
method: "POST",
body: JSON.stringify({
repo,
config: config || "rlm_call_traces",
split: split || "train",
}),
}),
getOverview: (dsId: string) =>
fetchJson<Record<string, unknown>>(`/datasets/${dsId}/overview`),
getExampleDetail: (dsId: string, exampleIdx: number) =>
fetchJson<Record<string, unknown>>(`/datasets/${dsId}/example/${exampleIdx}`),
getIterDetail: (dsId: string, exampleIdx: number, rlmIter: number) =>
fetchJson<Record<string, unknown>>(
`/datasets/${dsId}/example/${exampleIdx}/iter/${rlmIter}`
),
unloadDataset: (dsId: string) =>
fetchJson<{ status: string }>(`/datasets/${dsId}`, { method: "DELETE" }),
listPresets: () => fetchPresetsJson<Record<string, unknown>[]>(""),
createPreset: (preset: { name: string; repo: string; config: string; split: string }) =>
fetchPresetsJson<Record<string, unknown>>("", {
method: "POST",
body: JSON.stringify(preset),
}),
updatePreset: (id: string, data: { name: string }) =>
fetchPresetsJson<Record<string, unknown>>(`/${id}`, {
method: "PUT",
body: JSON.stringify(data),
}),
deletePreset: (id: string) =>
fetchPresetsJson<{ status: string }>(`/${id}`, { method: "DELETE" }),
};