Download tests/helpers.py from HassamGani/ReOrgBench: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/HassamGani/ReOrgBench/resolve/main/tests/helpers.py
- Command line
-
hf download hf://datasets/HassamGani/ReOrgBench/tests/helpers.py
-
curl -L -o helpers.py https://huggingface.co/datasets/HassamGani/ReOrgBench/resolve/main/tests/helpers.py
1.03 kB
| from __future__ import annotations | |
| from typing import Any | |
| from reorgbench.runtime import Episode | |
| from reorgbench.runtime.policy import AgentInfo, Observation | |
| class Script: | |
| """Per-agent action lists; an agent with nothing left does noop.""" | |
| def __init__(self, plans: dict[str, list[dict[str, Any]]]): | |
| self.plans = {k: list(v) for k, v in plans.items()} | |
| self.seen: dict[str, list[Observation]] = {} | |
| def __call__(self, info: AgentInfo): | |
| script = self | |
| class P: | |
| def act(self, obs: Observation) -> dict[str, Any]: | |
| script.seen.setdefault(info.id, []).append(obs) | |
| plan = script.plans.get(info.id, []) | |
| return plan.pop(0) if plan else {"type": "noop"} | |
| return P() | |
| def run_script(task, plans): | |
| script = Script(plans) | |
| res = Episode(task, script).run() | |
| return res, script | |
| def errors(res, kind=None): | |
| return [e for e in res.events if e["type"] == "error" and (kind is None or e["payload"]["kind"] == kind)] | |