vignesh1234 commited on
Commit
5d27894
·
verified ·
1 Parent(s): d23ccfe

Upload tools/eval/routing_check.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. tools/eval/routing_check.py +26 -0
tools/eval/routing_check.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Routing regression (ruling 2026-09-07): run after every serving change. No model is loaded.
2
+ Usage: .venv/bin/python eval/routing_check.py (exit 1 on any failure)"""
3
+ import json, os, sys
4
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
5
+ import serve as S
6
+ units = S.load_units()
7
+ cases = [json.loads(l) for l in open("eval/routing_cases.jsonl", encoding="utf-8") if l.strip()]
8
+ fails = 0
9
+ for c in cases:
10
+ stage, lit = S.decide_route(c["query"], units)
11
+ ok = stage == c["expected_stage"]
12
+ detail = ""
13
+ if ok and stage == "literature":
14
+ u = lit["unit"]
15
+ if "expected_unit" in c and str(u.get("number")) != str(c["expected_unit"]): ok = False
16
+ if "work_en" in c and u.get("work_en") != c["work_en"]: ok = False
17
+ if "section_adhikaram" in c and (u.get("section") or {}).get("adhikaram") != c["section_adhikaram"]: ok = False
18
+ if "title_contains" in c:
19
+ sec = u.get("section") or {}
20
+ hay = " ".join([str(sec.get("poem_title", "")), " ".join(u.get("text") or [])[:200]])
21
+ if c["title_contains"] not in hay: ok = False
22
+ detail = f" -> {u.get('work_en')} #{u.get('number')} ({lit['kind']}, {lit['mode']})"
23
+ print(("PASS " if ok else "FAIL ") + f"{c['query']:45s} expected {c['expected_stage']:11s} got {stage}{detail}")
24
+ fails += 0 if ok else 1
25
+ print(f"{len(cases) - fails}/{len(cases)} routing cases pass")
26
+ sys.exit(1 if fails else 0)