Repository navigation
Expand file tree
/
Copy pathfe-postprocess.py
More file actions
89 lines (67 loc) · 2.79 KB
/
Copy pathfe-postprocess.py
File metadata and controls
89 lines (67 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""FE meter post-processor for free-scan.sh results.
Adds an `fe_reading` field to each PASSING model in the results JSON by running
the 1 FE gauge against their endpoint. Uses the same OpenAI-compatible wiring
as free-scan.sh, so keyless endpoints are probed without authentication.
Usage (called from free-scan.sh):
python3 fe-postprocess.py <results.json> <fe-meter.py>
"""
import json
import sys
import subprocess
from pathlib import Path
from typing import Any
def run_fe_meter(model_id: str, base_url: str) -> dict | None:
"""Run fe_meter.py against a single model and return its reading.
Returns None if the meter fails (infra errors are treated as BELOW_FE-reachable).
"""
meter_path = Path(__file__).parent.parent / "independent-research" / "fe_meter.py"
import tempfile
import os
try:
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
out_file = f.name
result = subprocess.run(
[sys.executable, str(meter_path),
"--model", model_id,
"--host", base_url,
"--runs", "1", # Single run for roster integration (speed vs precision)
"--lengths", "2000", # Short test for fast scanning
"--out", out_file],
capture_output=True, text=True, timeout=120, check=True
)
with open(out_file) as f:
reading = json.load(f)
os.unlink(out_file)
return reading.get("reading", {"verdict": "ERROR"})
except (subprocess.TimeoutExpired, subprocess.CalledProcessError, json.JSONDecodeError, FileNotFoundError) as e:
if 'out_file' in locals() and os.path.exists(out_file):
os.unlink(out_file)
return {"verdict": f"ERROR:{type(e).__name__}"}
def main() -> int:
if len(sys.argv) < 2:
print("Usage: fe-postprocess.py <results.json>", file=sys.stderr)
return 1
results_path = sys.argv[1]
with open(results_path) as f:
data = json.load(f)
passing_ids = set(data.get("passing", []))
results = data.get("results", [])
print(f"[FE post-process] adding readings to {len(passing_ids)} PASSING models...", flush=True)
for i, result in enumerate(results):
model_id = result.get("id", "")
if model_id not in passing_ids:
continue
base_url = result.get("base_url", "")
if not base_url:
continue
print(f" [{i+1}/{len(results)}] {model_id} @ {base_url}", flush=True)
reading = run_fe_meter(model_id, base_url)
result["fe_reading"] = reading
# Write back
with open(results_path, "w") as f:
json.dump(data, f, indent=2)
print(f"[FE post-process] updated {results_path}", flush=True)
return 0
if __name__ == "__main__":
sys.exit(main())