Datasets:
CAI-Bench 5.2.0: capability, observer, reasons, coherence, hysteresis, recoverability and obligations splits (preregistered); headline score; train preference set; run_api.py
1b15694 verified Download tools/mock_api_server.py from compressionawareintelligence/cai-bench: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/datasets/compressionawareintelligence/cai-bench/resolve/refs%2Fpr%2F4/tools/mock_api_server.py
- Command line
-
hf download hf://datasets/compressionawareintelligence/cai-bench@refs/pr/4/tools/mock_api_server.py
-
curl -L -o mock_api_server.py https://huggingface.co/datasets/compressionawareintelligence/cai-bench/resolve/refs%2Fpr%2F4/tools/mock_api_server.py
1.07 kB
| """A tiny stand-in for the OpenAI and Anthropic APIs, for testing run_api.py with no key and no spending.""" | |
| import json, re, sys | |
| from http.server import BaseHTTPRequestHandler, HTTPServer | |
| LOG = [] | |
| class H(BaseHTTPRequestHandler): | |
| def log_message(self, *a): pass | |
| def do_POST(self): | |
| body = json.loads(self.rfile.read(int(self.headers["Content-Length"]))) | |
| with open(sys.argv[2], "a") as f: f.write(json.dumps({"path": self.path, "body": body}) + "\n") | |
| text = json.dumps(body) | |
| ans = "DECISION: YES" if "DECISION" in text else "OK" | |
| if "CHOICE:" in text: ans = "CHOICE: A" | |
| if "OWED:" in text: ans = "OWED: A, B" | |
| if self.path.endswith("/messages"): | |
| out = {"content": [{"type": "text", "text": ans}]} | |
| else: | |
| out = {"choices": [{"message": {"content": ans}}]} | |
| b = json.dumps(out).encode() | |
| self.send_response(200); self.send_header("Content-Type", "application/json"); self.end_headers(); self.wfile.write(b) | |
| HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever() | |