Spaces:
Running on Zero
Running on Zero
Router test v2: enumerate served models, probe candidates; syntax fix
Browse files170 unmodified lines171172173174175176177178179180181182183184185186187188189190191192193194195170 unmodified lines# ----------------------------------------------------------- stage: router testdef stage_router_test() -> dict:from openai import OpenAIrouter = OpenAI(base_url="https://router.huggingface.co/v1",api_key=os.environ["HF_TOKEN"])results = {}for model in ["openai/gpt-4o-mini", "anthropic/claude-sonnet-4-6"]:try:r = router.chat.completions.create(model=model,messages=[{"role": "user", "content": "Reply with exactly: OK"}],max_tokens=8,)results[model] = {"ok": True, "content": r.choices[0].message.content,"prompt_tokens": r.usage.prompt_tokens,"completion_tokens": r.usage.completion_tokens}except Exception as exc: # noqa: BLE001results[model] = {"ok": False, "error": repr(exc)[:500]}return {"results": results}def stage_mirror() -> dict:170 unmodified lines171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229170 unmodified lines# ----------------------------------------------------------- stage: router testdef _router_candidates(listing: dict) -> dict:gpt = ["openai/gpt-4o-mini", "gpt-4o-mini"]sonnet = ["anthropic/claude-sonnet-4-6", "claude-sonnet-4-6"]seen_g, seen_s = set(gpt), set(sonnet)for name in listing.get("all", []):low = name.lower()if "gpt-4o-mini" in low and name not in seen_g:gpt.append(name); seen_g.add(name)if "sonnet" in low and "claude" in low and name not in seen_s:sonnet.append(name); seen_s.add(name)return {"gpt": gpt[:6], "sonnet": sonnet[:6]}def _probe(router, candidates: list[str]) -> dict:attempts = {}for model in candidates:try:r = router.chat.completions.create(model=model,messages=[{"role": "user", "content": "Reply with exactly: OK"}],max_tokens=8,)attempts[model] = {"ok": True, "content": r.choices[0].message.content,"prompt_tokens": r.usage.prompt_tokens,"completion_tokens": r.usage.completion_tokens}return {"ok_model": model, "attempts": attempts,"detail": attempts[model]}except Exception as exc: # noqa: BLE001attempts[model] = {"ok": False, "error": repr(exc)[:300]}return {"ok_model": None, "attempts": attempts}def stage_router_test() -> dict:from openai import OpenAIrouter = OpenAI(base_url="https://router.huggingface.co/v1",api_key=os.environ["HF_TOKEN"])listing: dict = {}try:names = sorted(m.id for m in router.models.list())listing = {"total": len(names),"all": names,"gpt4omini_hits": [n for n in names if "gpt-4o-mini" in n.lower()],"claude_sonnet_hits": [n for n in namesif "sonnet" in n.lower() and "claude" in n.lower()],}except Exception as exc: # noqa: BLE001listing = {"error": repr(exc)[:400]}candidates = _router_candidates(listing)return {"listing": listing,"backbone": _probe(router, candidates["gpt"]),"judge": _probe(router, candidates["sonnet"])def stage_mirror() -> dict:
executor_entrypoint.py+46-12