()
| 43 | type BenchRow = { content: string; label: 'yes' | 'no' }; |
| 44 | |
| 45 | async 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 | |
| 62 | async function loadOrFetchRows(): Promise<BenchRow[]> { |
| 63 | if (fs.existsSync(CACHE_FILE)) { |
no test coverage detected