Something went wrong. Try again.
An agent harness for parametric learning.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041#!/usr/bin/env nodeimport { mkdir, readFile, writeFile } from "node:fs/promises";import { dirname, resolve } from "node:path";import { exportRecord } from "./export.js";import type { DpoExample, SftExample } from "./export.js";import type { PreferenceRecord } from "./types.js";
const inputPath = resolve(process.argv[2] ?? "data/preferences.jsonl");const outputPrefix = resolve(process.argv[3] ?? "data/training");
try { const records = (await readFile(inputPath, "utf8")) .split("\n") .filter(Boolean) .map((line) => JSON.parse(line) as PreferenceRecord); const sft: SftExample[] = []; const dpo: DpoExample[] = []; for (const record of records) { const examples = exportRecord(record); sft.push(examples.sft); dpo.push(...examples.dpo); }
const sftPath = `${outputPrefix}.sft.jsonl`; const dpoPath = `${outputPrefix}.dpo.jsonl`; await mkdir(dirname(outputPrefix), { recursive: true }); await Promise.all([ writeFile(sftPath, lines(sft), { encoding: "utf8", mode: 0o600 }), writeFile(dpoPath, lines(dpo), { encoding: "utf8", mode: 0o600 }), ]); process.stdout.write(`Exported ${sft.length} SFT examples to ${sftPath}\n`); process.stdout.write(`Exported ${dpo.length} preference pairs to ${dpoPath}\n`);} catch (error) { process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`); process.exitCode = 1;}
function lines(values: unknown[]): string { return values.map((value) => JSON.stringify(value)).join("\n") + (values.length ? "\n" : "");}