| |
| """Build the published Legora prompt-metadata JSONL from the prompt-bearing export. |
| |
| The 2026-08-05 Legora re-export (``data/raw/legora_2026-08-05_prompts.xlsx``) |
| carries the per-column question text of both runs in row 2: the left column |
| group belongs to ``legora-1``, the right one to ``legora-2`` (see |
| ``scripts/compare_legora_prompts.py`` / ``data/analysis/legora_prompt_comparison.md``). |
| This script writes one JSONL file per run with a record per field: |
| |
| {"model": "legora-1", "inference_date": "2026-08-01", "field": ..., "prompt": ...} |
| |
| python build_legora_prompts_jsonl.py --xlsx ../data/raw/legora_2026-08-05_prompts.xlsx \\ |
| --out-dir inference-results/prompts |
| """ |
| import argparse |
| import json |
| from pathlib import Path |
|
|
| import openpyxl |
|
|
| RUNS = ("legora-1", "legora-2") |
| INFERENCE_DATE = "2026-08-01" |
| PROMPT_SUFFIX = " (with prompt)" |
|
|
|
|
| def read_prompts(xlsx: Path) -> dict[str, dict[str, str]]: |
| """Return ``{model: {field: prompt}}`` from the export's prompt row.""" |
| wb = openpyxl.load_workbook(xlsx, data_only=True, read_only=True) |
| ws = wb.worksheets[0] |
| rows = ws.iter_rows(min_row=1, max_row=2, values_only=True) |
| header, prompt_row = next(rows), next(rows) |
| out: dict[str, dict[str, str]] = {run: {} for run in RUNS} |
| for head, prompt in zip(header, prompt_row): |
| if not head or not str(head).endswith(PROMPT_SUFFIX) or not prompt: |
| continue |
| field = str(head)[: -len(PROMPT_SUFFIX)] |
| run = RUNS[0] if field not in out[RUNS[0]] else RUNS[1] |
| out[run][field] = " ".join(str(prompt).split()) |
| return out |
|
|
|
|
| def main(argv: list[str] | None = None) -> int: |
| parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) |
| parser.add_argument("--xlsx", type=Path, |
| default=Path("../data/raw/legora_2026-08-05_prompts.xlsx")) |
| parser.add_argument("--out-dir", type=Path, default=Path("inference-results/prompts")) |
| args = parser.parse_args(argv) |
|
|
| prompts = read_prompts(args.xlsx) |
| args.out_dir.mkdir(parents=True, exist_ok=True) |
| for run, fields in prompts.items(): |
| dst = args.out_dir / f"prompts_{run.replace('-', '_')}.jsonl" |
| with dst.open("w", encoding="utf-8") as f: |
| for field, prompt in fields.items(): |
| record = {"model": run, "inference_date": INFERENCE_DATE, |
| "field": field, "prompt": prompt} |
| f.write(json.dumps(record, ensure_ascii=False) + "\n") |
| print(f"wrote {len(fields)} prompt record(s) to {dst}") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|