Download Biomanus/experiments/execution_audit/domain_env_reaudit_worker.py from czty/BioOcto: direct link, hf CLI and curl.
- Browser
- Download file 3.65 kB
-
https://huggingface.co/datasets/czty/BioOcto/resolve/main/Biomanus/experiments/execution_audit/domain_env_reaudit_worker.py
- Command line
-
hf download hf://datasets/czty/BioOcto/Biomanus/experiments/execution_audit/domain_env_reaudit_worker.py
-
curl -L -o domain_env_reaudit_worker.py https://huggingface.co/datasets/czty/BioOcto/resolve/main/Biomanus/experiments/execution_audit/domain_env_reaudit_worker.py
3.65 kB
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import argparse | |
| import ast | |
| import csv | |
| import importlib.util | |
| import json | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| PROJECT_ROOT = Path("/225040511/project/Beyond_Prompt-Based_Planning/Biomanus") | |
| AUDIT_SCRIPT = PROJECT_ROOT / "experiments/execution_audit/audit_bioinfomcp_execution.py" | |
| PREVIOUS_AUDIT = PROJECT_ROOT / "experiments/execution_audit/results_300/tool_fixture_audit.csv" | |
| MCP_ROOT = PROJECT_ROOT / "biomni_web/backend/data/mcp_generated" | |
| def load_audit_module(): | |
| spec = importlib.util.spec_from_file_location("execution_audit_module", AUDIT_SCRIPT) | |
| if spec is None or spec.loader is None: | |
| raise RuntimeError(f"cannot import {AUDIT_SCRIPT}") | |
| module = importlib.util.module_from_spec(spec) | |
| sys.modules[spec.name] = module | |
| spec.loader.exec_module(module) | |
| return module | |
| def domain_group(category: str) -> str: | |
| if category in {"single_cell", "transcriptomics", "genomics"}: | |
| return category | |
| return "other" | |
| def parse_schema(value: str): | |
| try: | |
| return ast.literal_eval(value) | |
| except Exception: | |
| return {} | |
| def write_csv(path: Path, rows: list[dict]): | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| if not rows: | |
| path.write_text("") | |
| return | |
| fieldnames = sorted({key for row in rows for key in row}) | |
| with path.open("w", newline="") as handle: | |
| writer = csv.DictWriter(handle, fieldnames=fieldnames) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--group", required=True, choices=["single_cell", "transcriptomics", "genomics", "other"]) | |
| parser.add_argument("--out-dir", type=Path, required=True) | |
| parser.add_argument("--timeout", type=float, default=20) | |
| args = parser.parse_args() | |
| audit = load_audit_module() | |
| previous_rows = list(csv.DictReader(PREVIOUS_AUDIT.open())) | |
| items = [] | |
| for row in previous_rows: | |
| if domain_group(row.get("category", "")) != args.group: | |
| continue | |
| items.append( | |
| { | |
| "category": row.get("category", ""), | |
| "server": row.get("server", ""), | |
| "tool": row.get("tool", ""), | |
| "schema": parse_schema(row.get("schema", "")), | |
| "previous_ok": row.get("ok", ""), | |
| "previous_error_type": row.get("error_type", ""), | |
| } | |
| ) | |
| rows = [] | |
| for idx, item in enumerate(items, 1): | |
| result = audit.audit_tool_call(MCP_ROOT, item, args.timeout) | |
| result["domain_env_group"] = args.group | |
| rows.append(result) | |
| if idx % 10 == 0: | |
| print(f"[{args.group}] audited {idx}/{len(items)}", flush=True) | |
| out_csv = args.out_dir / f"{args.group}_tool_fixture_reaudit.csv" | |
| write_csv(out_csv, rows) | |
| ok_count = sum(1 for row in rows if row.get("ok")) | |
| summary = { | |
| "group": args.group, | |
| "n_tested": len(rows), | |
| "n_success": ok_count, | |
| "success_rate": f"{100 * ok_count / len(rows):.1f}%" if rows else "n/a", | |
| "previous_success": sum(1 for row in rows if str(row.get("previous_ok")).lower() == "true"), | |
| "error_taxonomy": dict(Counter(row.get("error_type", "none") for row in rows if not row.get("ok"))), | |
| "output_csv": str(out_csv), | |
| "python": sys.executable, | |
| } | |
| (args.out_dir / f"{args.group}_summary.json").write_text(json.dumps(summary, indent=2, sort_keys=True)) | |
| print(json.dumps(summary, indent=2, sort_keys=True), flush=True) | |
| if __name__ == "__main__": | |
| main() | |