Download scripts/120_operational_router.py from koreallmdev/dgx-harness-engineering: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/koreallmdev/dgx-harness-engineering/resolve/main/scripts/120_operational_router.py
- Command line
-
hf download hf://koreallmdev/dgx-harness-engineering/scripts/120_operational_router.py
-
curl -L -o 120_operational_router.py https://huggingface.co/koreallmdev/dgx-harness-engineering/resolve/main/scripts/120_operational_router.py
1.53 kB
| #!/usr/bin/env python3 | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path("/home/harness_user_1/dgx_ai_factory") | |
| ROUTER_JSON = ROOT / "router_templates/operational_router_v1.json" | |
| def load_router(): | |
| return json.loads(ROUTER_JSON.read_text(encoding="utf-8")) | |
| def route(prompt: str): | |
| router = load_router() | |
| low = prompt.lower() | |
| best = None | |
| best_hits = 0 | |
| for r in router.get("routes", []): | |
| hits = sum(1 for kw in r.get("keywords_any", []) if kw.lower() in low) | |
| if hits > best_hits: | |
| best = r | |
| best_hits = hits | |
| if best and best_hits >= 1: | |
| return { | |
| "routed": True, | |
| "route_id": best.get("id"), | |
| "category": best.get("category"), | |
| "hits": best_hits, | |
| "answer": best.get("answer"), | |
| } | |
| return { | |
| "routed": False, | |
| "route_id": None, | |
| "category": "model", | |
| "hits": 0, | |
| "answer": router.get("fallback", {}).get("answer", "ROUTE_TO_CHAMPION_MODEL"), | |
| } | |
| def main(): | |
| if len(sys.argv) < 2: | |
| print("usage: python scripts/120_operational_router.py '질문'") | |
| node-7.example.invalid SystemExit(2) | |
| prompt = " ".join(sys.argv[1:]) | |
| result = route(prompt) | |
| print("==== ROUTER RESULT ====") | |
| print("routed:", result["routed"]) | |
| print("route_id:", result["route_id"]) | |
| print("category:", result["category"]) | |
| print("hits:", result["hits"]) | |
| print() | |
| print(result["answer"]) | |
| if __name__ == "__main__": | |
| main() | |