"""Sample N parallel "Program and Code" conversations and write each language as .funes.jsonl. usage: python3 convert.py N SEED writes corpus/{zh,en}/.funes.jsonl and corpus/ids.txt """ import json, random, sys from pathlib import Path n, seed = int(sys.argv[1]), int(sys.argv[2]) src = Path("sharegpt_jsonl") def load(name): out = {} for line in open(src / name, encoding="utf-8"): r = json.loads(line) if r.get("category") == "Program and Code" and r.get("conversation"): out[r["conversation_id"]] = r["conversation"] return out zh = load("computer_zh_26k(fixed).jsonl") en = load("computer_en_26k(fixed).jsonl") both = sorted( cid for cid in zh.keys() & en.keys() if ":" not in cid and len(zh[cid]) == len(en[cid]) ) print(f"{len(zh)} zh, {len(en)} en, {len(both)} parallel with matching turn counts") ids = random.Random(seed).sample(both, n) for lang, convs in (("zh", zh), ("en", en)): d = Path("corpus") / lang d.mkdir(parents=True, exist_ok=True) for i, cid in enumerate(ids): ts = f"2026-01-{1 + i % 28:02d}T{(i // 28) % 24:02d}:00:00Z" lines, seq = [], 0 for pair in convs[cid]: for role, key in (("user", "human"), ("assistant", "assistant")): text = pair.get(key) or "" lines.append(json.dumps({ "session_id": cid, "turn_uuid": f"t{seq}", "seq": seq, "ts": ts, "role": role, "harness": "sharegpt", "blocks": [{"block_type": "text", "text": text}] if text else [], }, ensure_ascii=False)) seq += 1 (d / f"{cid}.funes.jsonl").write_text("\n".join(lines) + "\n", encoding="utf-8") Path("corpus/ids.txt").write_text("\n".join(ids) + "\n") print(f"wrote {n} conversations per language")