Download validator.py from RegalFire/GameAgent-Recovery-100K: direct link, hf CLI and curl.
- Browser
- Download file 3.94 kB
-
https://huggingface.co/datasets/RegalFire/GameAgent-Recovery-100K/resolve/main/validator.py
- Command line
-
hf download hf://datasets/RegalFire/GameAgent-Recovery-100K/validator.py
-
curl -L -o validator.py https://huggingface.co/datasets/RegalFire/GameAgent-Recovery-100K/resolve/main/validator.py
3.94 kB
| from __future__ import annotations | |
| import argparse,json,hashlib | |
| from pathlib import Path | |
| from collections import Counter | |
| def canon(x): | |
| return json.dumps(x,sort_keys=True,separators=(",",":"),ensure_ascii=False) | |
| def sha(x): | |
| return hashlib.sha256(canon(x).encode()).hexdigest() | |
| def oracle(r): | |
| f=r["family"] | |
| s=r["state_before_failure"] | |
| if f=="wrong_target": | |
| ns=dict(s); ns["selected"]="objective_A" | |
| return "select_objective_A",ns | |
| if f=="navigation_loop": | |
| ns=dict(s); ns["x"]=s["x"]+1; ns["visited_same_cell"]=0 | |
| return "move_east",ns | |
| if f=="missing_prerequisite": | |
| ns=dict(s); ns["has_key"]=True; ns["key_visible"]=False | |
| return "pickup_key",ns | |
| if f=="premature_interaction": | |
| ns=dict(s); ns["distance_to_terminal"]-=1 | |
| return "move_closer",ns | |
| if f=="resource_exhaustion": | |
| ns=dict(s); ns["ammo"]=s["reserve_ammo"]; ns["reserve_ammo"]=0 | |
| return "reload",ns | |
| if f=="low_health_attack": | |
| ns=dict(s); ns["hp"]=min(100,s["hp"]+35); ns["medkits"]=0 | |
| return "heal",ns | |
| if f=="locked_door": | |
| ns=dict(s); ns["door_locked"]=False | |
| return "unlock_door",ns | |
| if f=="missing_tool": | |
| ns=dict(s); ns["has_tool"]=True; ns["tool_visible"]=False | |
| return "pickup_tool",ns | |
| if f=="failed_extraction": | |
| ns=dict(s); ns["collected"]=s["required"] | |
| return "collect_remaining_item",ns | |
| if f=="wrong_sequence": | |
| ns=dict(s) | |
| if s["stage"]==0: | |
| ns["token"]=True; ns["stage"]=1 | |
| return "pickup_token",ns | |
| if s["stage"]==1: | |
| ns["terminal"]=True; ns["stage"]=2 | |
| return "unlock_terminal",ns | |
| ns["vault"]=True; ns["stage"]=3 | |
| return "open_vault",ns | |
| raise ValueError(f) | |
| def validate(path): | |
| ids=set(); fps=set(); fams=Counter(); splits=Counter(); count=0 | |
| with path.open("r",encoding="utf-8") as f: | |
| for line in f: | |
| if not line.strip(): continue | |
| r=json.loads(line); count+=1 | |
| if r["id"] in ids: raise ValueError("duplicate id") | |
| if r["fingerprint_sha256"] in fps: raise ValueError("duplicate fingerprint") | |
| ids.add(r["id"]); fps.add(r["fingerprint_sha256"]) | |
| body={k:v for k,v in r.items() if k not in {"id","fingerprint_sha256"}} | |
| if sha(body)[:32]!=r["id"]: | |
| raise ValueError(f"id mismatch {r['id']}") | |
| w=dict(body); w["id"]=r["id"] | |
| if sha(w)!=r["fingerprint_sha256"]: | |
| raise ValueError(f"fingerprint mismatch {r['id']}") | |
| action,state=oracle(r) | |
| if action!=r["recovery_action"]: | |
| raise ValueError(f"recovery action {r['id']}") | |
| if state!=r["state_after_recovery"]: | |
| raise ValueError(f"recovery state {r['id']}") | |
| if r["failed_action"]==r["recovery_action"]: | |
| raise ValueError(f"failure equals recovery {r['id']}") | |
| p=r["provenance"] | |
| if ( | |
| not p["synthetic"] | |
| or p["copied_records"]!=0 | |
| or p["copyrighted_gameplay"] | |
| or p["contains_pii"] | |
| or p["llm_generated_ground_truth"] | |
| ): | |
| raise ValueError("provenance") | |
| fams[r["family"]]+=1 | |
| splits[r["split"]]+=1 | |
| return { | |
| "status":"PASS", | |
| "validated":count, | |
| "unique_ids":len(ids), | |
| "unique_fingerprints":len(fps), | |
| "families":dict(fams), | |
| "splits":dict(splits) | |
| } | |
| def main(): | |
| ap=argparse.ArgumentParser() | |
| ap.add_argument("dataset",type=Path) | |
| ap.add_argument("--report",type=Path) | |
| a=ap.parse_args() | |
| report=validate(a.dataset) | |
| if a.report: | |
| a.report.write_text(json.dumps(report,indent=2),encoding="utf-8") | |
| print(json.dumps(report)) | |
| if __name__=="__main__": | |
| main() | |