MCPcopy Index your code
hub / github.com/garrytan/gstack / fetchDatasetSample

Function fetchDatasetSample

browse/test/security-bench.test.ts:45–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43type BenchRow = { content: string; label: 'yes' | 'no' };
44
45async function fetchDatasetSample(): Promise<BenchRow[]> {
46 const rows: BenchRow[] = [];
47 // HF datasets-server caps at 100 rows per request.
48 for (let offset = 0; rows.length < SAMPLE_SIZE; offset += 100) {
49 const length = Math.min(100, SAMPLE_SIZE - rows.length);
50 const url = `${HF_API}&offset=${offset}&length=${length}`;
51 const res = await fetch(url);
52 if (!res.ok) throw new Error(`HF API ${res.status}: ${url}`);
53 const data = (await res.json()) as { rows: Array<{ row: BenchRow }> };
54 if (!data.rows?.length) break;
55 for (const r of data.rows) {
56 rows.push({ content: r.row.content, label: r.row.label as 'yes' | 'no' });
57 }
58 }
59 return rows;
60}
61
62async function loadOrFetchRows(): Promise<BenchRow[]> {
63 if (fs.existsSync(CACHE_FILE)) {

Callers 1

loadOrFetchRowsFunction · 0.85

Calls 2

fetchFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected