"""Run the public course questions; save actual tool observations and answers.""" import argparse import json import sys from pathlib import Path from datetime import datetime, timezone import requests from agent import API, EvidenceAgent if __name__ == "__main__": sys.stdout.reconfigure(encoding="utf-8") parser = argparse.ArgumentParser() parser.add_argument("--limit", type=int, default=20) parser.add_argument("--model", default="qwen2.5:7b") parser.add_argument("--task", default=None) parser.add_argument("--retry-unknown", action="store_true") parser.add_argument("--retry-all", action="store_true") parser.add_argument("--controller", action="store_true", help="Use an external LLM through the file IPC adapter") parser.add_argument("--web-controller", action="store_true", help="Use external public web tools through the IPC adapter") parser.add_argument("--offline-cache", action="store_true", help="Use the previously retrieved official question list") args = parser.parse_args() questions = json.loads(Path("questions_cache.json").read_text(encoding="utf-8")) if args.offline_cache else requests.get(f"{API}/questions", timeout=30).json() path = Path("evaluation_full_results.json") results = json.loads(path.read_text(encoding="utf-8")) if path.exists() else [] completed = set() if args.retry_all else {r["task_id"] for r in results if not args.retry_unknown or r["answer"] != "UNKNOWN"} if args.controller and not args.retry_all: completed &= {r["task_id"] for r in results if r.get("model") == "ChatGPT Work Mode controller" and not r.get("error")} if args.web_controller: import agent as agent_module from controller import ControllerWebTools web = ControllerWebTools() agent_module.search_web = web.search_web agent_module.read_page = web.read_page agent_module.FUNCTIONS.update(search_web=web.search_web, read_page=web.read_page) if args.controller: from controller import ControllerModel agent = EvidenceAgent(model="ChatGPT Work Mode controller", completion=ControllerModel()) else: agent = EvidenceAgent(model=args.model) for item in questions[:args.limit]: if item["task_id"] in completed or (args.task and item["task_id"] != args.task): continue print("START", item["task_id"], item["question"][:100], flush=True) try: run = agent.solve(item["question"], item["task_id"], item["file_name"]) except Exception as error: run = {"answer": "UNKNOWN", "tools": [], "error": f"{type(error).__name__}: {error}"} previous = [r for r in results if r["task_id"] == item["task_id"]] results = [r for r in results if r["task_id"] != item["task_id"]] results.append({**item, **run, "run_at": datetime.now(timezone.utc).isoformat(), "previous_attempts": previous}) path.write_text(json.dumps(results, ensure_ascii=False, indent=2), encoding="utf-8") print("ANSWER", run["answer"], "TOOLS", len(run.get("tools", [])), flush=True) from publish_results import compact_results Path("evaluation_results.json").write_text(json.dumps(compact_results(results), ensure_ascii=False, indent=2), encoding="utf-8")