"""Feed label-free JSONL to a local adapter; save validated JSON predictions. Example: python run_model.py --output predictions.json -- python adapter.py The adapter reads question objects as JSONL on stdin and emits one JSONL object {id, prediction} per question on stdout. Logs belong on stderr. This is a local process launcher, not a sandbox; inspect the adapter and disable network yourself. """ import argparse import json from pathlib import Path import subprocess from benchmark import DATASET, normalise_predictions, read_rows, dump def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--questions", default=str(DATASET / "questions/test.jsonl")) parser.add_argument("--output", default="predictions.json") parser.add_argument("--timeout", type=float, default=600) parser.add_argument("command", nargs=argparse.REMAINDER) args = parser.parse_args() command = args.command[1:] if args.command[:1] == ["--"] else args.command if not command: parser.error("Provide an adapter command after --") rows = read_rows(args.questions) if any("answer" in r or "program" in r for r in rows): parser.error("Use label-free questions/, not data/ or audit.jsonl") result = subprocess.run(command, input="".join(json.dumps(r) + "\n" for r in rows), capture_output=True, text=True, encoding="utf-8", timeout=args.timeout, check=True) predictions = [json.loads(line) for line in result.stdout.splitlines() if line.strip()] normalise_predictions(predictions, rows) dump(args.output, predictions) print(f"Validated {len(predictions)} predictions; wrote {Path(args.output).resolve()}") if __name__ == "__main__": main()