Datasets:
Download klein_code_bench/build.py from klein-ml/klein-code-bench: direct link, hf CLI and curl.
- Browser
- Download file 3.77 kB
-
https://huggingface.co/datasets/klein-ml/klein-code-bench/resolve/main/klein_code_bench/build.py
- Command line
-
hf download hf://datasets/klein-ml/klein-code-bench/klein_code_bench/build.py
-
curl -L -o build.py https://huggingface.co/datasets/klein-ml/klein-code-bench/resolve/main/klein_code_bench/build.py
3.77 kB
| """Reproducibly compile contracts and static acceptance suites into HF JSONL.""" | |
| from __future__ import annotations | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| from .catalog import FAMILIES | |
| from .protocol import PROTOCOL_VERSION, TIERS, contract | |
| from .reference.domains import solve | |
| from .scenarios import expected_scenarios | |
| def dumps(value): | |
| return json.dumps( | |
| value, | |
| ensure_ascii=False, | |
| sort_keys=True, | |
| separators=(",", ":"), | |
| allow_nan=False, | |
| ) | |
| def build(destination=None): | |
| root = Path(destination) if destination else Path(__file__).parent / "data" | |
| root.mkdir(parents=True, exist_ok=True) | |
| counts, hashes, assertions = {}, {}, {} | |
| for tier, models in TIERS.items(): | |
| rows = [] | |
| for index, f in enumerate(FAMILIES.values(), 1): | |
| # Hand-written goldens are independent of the oracle code. | |
| if solve(f.slug, f.inputs[0]) != f.golden: | |
| raise ValueError(f"Golden mismatch: {f.slug}") | |
| tests = expected_scenarios(f.slug, tier) | |
| examples = [ | |
| { | |
| "request": {"op": "solve", "input": x}, | |
| "response": {"ok": True, "result": solve(f.slug, x)}, | |
| } | |
| for x in f.inputs[:2] | |
| ] | |
| task_id = f"kcb-{tier}-{index:03d}-{f.slug.replace('_', '-')}" | |
| title = ( | |
| f"{f.slug.replace('_', ' ').title()} — " | |
| + { | |
| "easy": "CLI project", | |
| "intermediate": "workspace service", | |
| "hard": "transactional service", | |
| "max": "durable service", | |
| }[tier] | |
| ) | |
| prompt = ( | |
| f"# {title}\n\n" | |
| + contract(tier) | |
| + "\nDomain contract:\n" | |
| + f.specification | |
| + "\nRequired input fields: " | |
| + ", ".join(f.required) | |
| + ".\n\nExamples:\n" | |
| + json.dumps(examples, indent=2, ensure_ascii=False) | |
| ) | |
| rows.append( | |
| { | |
| "task_id": task_id, | |
| "subset": tier, | |
| "family": f.slug, | |
| "title": title, | |
| "category": f.category, | |
| "target_model_parameters": models, | |
| "language": "python", | |
| "entrypoint": "main.py", | |
| "protocol_version": PROTOCOL_VERSION, | |
| "prompt": prompt, | |
| "timeout_seconds": 10, | |
| "public_tests": dumps(examples), | |
| "acceptance_tests": dumps(tests), | |
| "num_scenarios": len(tests), | |
| "num_assertions": sum( | |
| len(s["expected"]) for t in tests for s in t["sessions"] | |
| ), | |
| } | |
| ) | |
| file = root / f"{tier}.jsonl" | |
| file.write_text("".join(dumps(r) + "\n" for r in rows), encoding="utf-8") | |
| counts[tier] = len(rows) | |
| assertions[tier] = sum(r["num_assertions"] for r in rows) | |
| hashes[file.name] = hashlib.sha256(file.read_bytes()).hexdigest() | |
| manifest = { | |
| "benchmark": "Klein-Code-Bench", | |
| "version": "0.1.0", | |
| "protocol_version": PROTOCOL_VERSION, | |
| "tasks": 260, | |
| "families": 65, | |
| "counts": counts, | |
| "assertions": assertions, | |
| "sha256": hashes, | |
| "seed": 1729, | |
| "difficulty_calibrated": False, | |
| } | |
| (root / "manifest.json").write_text( | |
| json.dumps(manifest, indent=2) + "\n", encoding="utf-8" | |
| ) | |
| return manifest | |
| if __name__ == "__main__": | |
| print(json.dumps(build(), indent=2)) | |