Spaces:
Restarting
Restarting
fix(code): broaden HF token detection so a11oy Code flips to generative
Browse files- a11oy_code_engine.py +15 -1
a11oy_code_engine.py
CHANGED
|
@@ -441,7 +441,21 @@ def _sandbox_exec(code: str, lang: str = "python", timeout_s: int = 6,
|
|
| 441 |
# (2) HF router IF a token is present (disclosed)
|
| 442 |
# (3) local DETERMINISTIC, retrieval-grounded responder (honest label)
|
| 443 |
# ===========================================================================
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
_LOCAL_MODEL_CMD = os.environ.get("A11OY_LOCAL_MODEL_CMD") or ""
|
| 446 |
|
| 447 |
# ---------------------------------------------------------------------------
|
|
|
|
| 441 |
# (2) HF router IF a token is present (disclosed)
|
| 442 |
# (3) local DETERMINISTIC, retrieval-grounded responder (honest label)
|
| 443 |
# ===========================================================================
|
| 444 |
+
# Token detection: read HF_TOKEN first, then a broad set of common fallback names so a
|
| 445 |
+
# correctly-pasted token is picked up regardless of which secret NAME it was saved under
|
| 446 |
+
# (HF Space secrets are sometimes saved as 'Token', 'HF_ROUTER_TOKEN', etc.). Values are
|
| 447 |
+
# stripped of stray whitespace/quotes. Server-side only; never sent to the browser.
|
| 448 |
+
def _detect_hf_token() -> str:
|
| 449 |
+
for _name in ("HF_TOKEN", "HUGGING_FACE_HUB_TOKEN", "HF_ROUTER_TOKEN",
|
| 450 |
+
"HF_API_TOKEN", "HUGGINGFACE_TOKEN", "HUGGINGFACEHUB_API_TOKEN", "Token"):
|
| 451 |
+
_v = os.environ.get(_name)
|
| 452 |
+
if _v:
|
| 453 |
+
_v = _v.strip().strip('"').strip("'").strip()
|
| 454 |
+
if _v.startswith("hf_") or len(_v) >= 20:
|
| 455 |
+
return _v
|
| 456 |
+
return ""
|
| 457 |
+
|
| 458 |
+
_HF_TOKEN = _detect_hf_token()
|
| 459 |
_LOCAL_MODEL_CMD = os.environ.get("A11OY_LOCAL_MODEL_CMD") or ""
|
| 460 |
|
| 461 |
# ---------------------------------------------------------------------------
|