Download v13/scripts/check.py from ajinkyamulay/analyst-workbench: direct link, hf CLI and curl.
- Browser
- Download file 2.08 kB
-
https://huggingface.co/datasets/ajinkyamulay/analyst-workbench/resolve/main/v13/scripts/check.py
- Command line
-
hf download hf://datasets/ajinkyamulay/analyst-workbench/v13/scripts/check.py
-
curl -L -o check.py https://huggingface.co/datasets/ajinkyamulay/analyst-workbench/resolve/main/v13/scripts/check.py
2.08 kB
| """Admission checks for v13 tasks against a running server: the reference solution must | |
| score 1.0, doing nothing must score 0.0, and an optional strawman (solution/strawman.py) | |
| must score 0.0. | |
| python check.py http://127.0.0.1:18501 tasks_dir [task_id ...] | |
| """ | |
| import json, sys | |
| from pathlib import Path | |
| from websockets.sync.client import connect | |
| def play(url, task_id, script=None, verbose=False): | |
| with connect(url.replace("http", "ws", 1) + "/ws", open_timeout=30, max_size=2**24) as ws: | |
| def send(msg): | |
| ws.send(json.dumps(msg)); return json.loads(ws.recv(timeout=600))["data"] | |
| d = send({"type": "reset", "data": {"task_id": task_id}}) | |
| if verbose: | |
| print(" reset obs keys", sorted(d["observation"]), "instruction chars", len(d["observation"]["instruction"])) | |
| if script is not None: | |
| send({"type": "step", "data": {"action_type": "write_file", "file_path": "/tmp/_solve.py", "content": script}}) | |
| r = send({"type": "step", "data": {"action_type": "exec", "command": "python3 /tmp/_solve.py && rm /tmp/_solve.py"}}) | |
| if verbose: | |
| print(" exec ->", json.dumps(r["observation"])[:300]) | |
| d = send({"type": "step", "data": {"action_type": "evaluate"}}) | |
| if verbose: | |
| print(" evaluate ->", json.dumps({k: d[k] for k in ("reward", "done")}), json.dumps(d["observation"])[:400]) | |
| return d["reward"], d["done"] | |
| url, tasks = sys.argv[1], Path(sys.argv[2]) | |
| ids = sys.argv[3:] or sorted(p.name for p in tasks.iterdir() if (p / "instruction.md").exists()) | |
| bad = 0 | |
| for t in ids: | |
| sol = (tasks / t / "solution" / "solve.py").read_text() | |
| ok = play(url, t, sol, verbose=len(ids) == 1) | |
| empty = play(url, t) | |
| straw = tasks / t / "solution" / "strawman.py" | |
| sw = play(url, t, straw.read_text()) if straw.exists() else None | |
| good = ok[0] == 1.0 and empty[0] == 0.0 and (sw is None or sw[0] == 0.0) | |
| bad += not good | |
| print(f"{'OK ' if good else 'BAD'} {t}: reference {ok}, empty {empty}, strawman {sw}") | |
| sys.exit(1 if bad else 0) | |