-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm-build.js
More file actions
35 lines (32 loc) · 1.33 KB
/
llm-build.js
File metadata and controls
35 lines (32 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// llm-build.js — Validate & merge llm/<kb>/*.jsonl → llm/<kb>/merged.jsonl
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const LLM_ROOT = "llm";
function mergeOne(kb) {
const dir = path.join(LLM_ROOT, kb);
const files = glob.sync(path.join(dir, "**/*.jsonl"));
if (!files.length) { console.warn(`(skip) No JSONL in ${dir}`); return; }
const out = [];
for (const f of files) {
const lines = fs.readFileSync(f, "utf8").split(/\r?\n/).filter(Boolean);
for (const ln of lines) {
try { JSON.parse(ln); out.push(ln); } catch { console.warn(`(skip bad) ${f}`); }
}
}
const outPath = path.join(dir, "merged.jsonl");
fs.writeFileSync(outPath, out.join("\n") + "\n", "utf8");
console.log(`✅ Built ${outPath} (${out.length} examples).`);
}
(function main() {
if (!fs.existsSync(LLM_ROOT)) { console.error("No ./llm folder"); process.exit(1); }
const arg = process.argv[2];
if (arg) {
if (!fs.existsSync(path.join(LLM_ROOT, arg))) { console.error(`Folder not found: llm/${arg}`); process.exit(1); }
mergeOne(arg);
} else {
const subs = fs.readdirSync(LLM_ROOT, { withFileTypes: true }).filter(d => d.isDirectory()).map(d => d.name);
if (!subs.length) { console.error("No subfolders in ./llm"); process.exit(1); }
for (const name of subs) mergeOne(name);
}
})();