Download code/vc_install.py from badr7/rapidchat-data: direct link, hf CLI and curl.
- Browser
- Download file 2.86 kB
-
https://huggingface.co/datasets/badr7/rapidchat-data/resolve/main/code/vc_install.py
- Command line
-
hf download hf://datasets/badr7/rapidchat-data/code/vc_install.py
-
curl -L -o vc_install.py https://huggingface.co/datasets/badr7/rapidchat-data/resolve/main/code/vc_install.py
2.86 kB
| #!/usr/bin/env python3 | |
| """Registers the Viperclaw bench as the tau2 domain "vc_airline" (same policy and tools as airline, own database and tasks). | |
| usage: vc_install.py <tau2-bench repo dir> <bench dir with db.json, tasks.json, split_tasks.json> | |
| Safe to run more than once. | |
| """ | |
| import os | |
| import shutil | |
| import sys | |
| repo, bench = sys.argv[1], sys.argv[2] | |
| data_dir = os.path.join(repo, "data", "tau2", "domains", "vc_airline") | |
| os.makedirs(data_dir, exist_ok=True) | |
| for name in ("db.json", "tasks.json", "split_tasks.json"): | |
| shutil.copyfile(os.path.join(bench, name), os.path.join(data_dir, name)) | |
| env_py = os.path.join(repo, "src", "tau2", "domains", "airline", "vc_environment.py") | |
| open(env_py, "w").write('''"""Viperclaw bench: the airline policy and tools on a re-skinned database with generated tasks.""" | |
| from typing import Optional | |
| from tau2.data_model.tasks import Task | |
| from tau2.domains.airline.data_model import FlightDB | |
| from tau2.domains.airline.tools import AirlineTools | |
| from tau2.domains.airline.utils import AIRLINE_POLICY_PATH | |
| from tau2.environment.environment import Environment | |
| from tau2.utils import load_file | |
| from tau2.utils.utils import DATA_DIR | |
| VC_DIR = DATA_DIR / "tau2" / "domains" / "vc_airline" | |
| def get_environment(db: Optional[FlightDB] = None, solo_mode: bool = False) -> Environment: | |
| if solo_mode: | |
| raise ValueError("Airline domain does not support solo mode") | |
| if db is None: | |
| db = FlightDB.load(VC_DIR / "db.json") | |
| with open(AIRLINE_POLICY_PATH, "r") as fp: | |
| policy = fp.read() | |
| # the domain name must be this one: tau2 grades each conversation against the environment registered under it | |
| return Environment(domain_name="vc_airline", policy=policy, tools=AirlineTools(db)) | |
| def get_tasks_split() -> dict[str, list[str]]: | |
| return load_file(VC_DIR / "split_tasks.json") | |
| def get_tasks(task_split_name: Optional[str] = "base") -> list[Task]: | |
| tasks = [Task.model_validate(task) for task in load_file(VC_DIR / "tasks.json")] | |
| if task_split_name is None: | |
| return tasks | |
| wanted = set(get_tasks_split()[task_split_name]) | |
| return [task for task in tasks if task.id in wanted] | |
| ''') | |
| reg_py = os.path.join(repo, "src", "tau2", "registry.py") | |
| src = open(reg_py).read() | |
| if "vc_airline" not in src: | |
| anchor = ' registry.register_domain(retail_domain_get_environment, "retail")' | |
| assert src.count(anchor) == 1, "registry.py layout changed; cannot find the retail registration line" | |
| block = (' from tau2.domains.airline import vc_environment as _vc\n' | |
| ' registry.register_domain(_vc.get_environment, "vc_airline")\n' | |
| ' registry.register_tasks(_vc.get_tasks, "vc_airline", get_task_splits=_vc.get_tasks_split)\n\n') | |
| open(reg_py, "w").write(src.replace(anchor, block + anchor)) | |
| print("vc_airline domain installed in", repo) | |