Spaces:
Running
Running
chore(sync): mirror backend .py + Dockerfile to Space (hf-sync-backend)
Browse filesAutomated backend sync from szl-holdings/a11oy main via hf-sync-backend.
Updated (differed from the Space): a11oy_code_engine.py, a11oy_code_orchestrator.py
Deleted (gone from the repo + Dockerfile COPY set): (none)
Keeps the Space-built backend (serve.py + the Dockerfile-COPY'd .py
modules) identical to GitHub main so the Space never rebuilds from a
stale backend, new endpoints don't 404 there, and orphaned modules
removed from the repo don't linger in the Space tree.
- a11oy_code_engine.py +7 -4
- a11oy_code_orchestrator.py +29 -4
a11oy_code_engine.py
CHANGED
|
@@ -530,12 +530,15 @@ _GPU_LABEL = (os.environ.get("A11OY_GPU_LABEL") or "").strip()
|
|
| 530 |
# ---------------------------------------------------------------------------
|
| 531 |
# MODEL-ENDPOINT ADAPTER (sovereign, swappable).
|
| 532 |
# Default target = the OpenAI-compatible Hugging Face Router. A single env var
|
| 533 |
-
#
|
| 534 |
-
#
|
| 535 |
-
# changes. The token is read server-side
|
|
|
|
|
|
|
| 536 |
# Open-weight roster only — no closed (GPT/Claude/Gemini) models.
|
| 537 |
# ---------------------------------------------------------------------------
|
| 538 |
-
_MODEL_BASE_URL = (os.environ.get("
|
|
|
|
| 539 |
or os.environ.get("HF_ROUTER_BASE")
|
| 540 |
or "https://router.huggingface.co/v1").rstrip("/")
|
| 541 |
|
|
|
|
| 530 |
# ---------------------------------------------------------------------------
|
| 531 |
# MODEL-ENDPOINT ADAPTER (sovereign, swappable).
|
| 532 |
# Default target = the OpenAI-compatible Hugging Face Router. A single env var
|
| 533 |
+
# (A11OY_BRAIN_URL, canonical; A11OY_MODEL_BASE_URL accepted as alias) repoints
|
| 534 |
+
# this at an owned sovereign node (on-box SGLang/vLLM, any OpenAI-compatible
|
| 535 |
+
# /chat/completions server) WITHOUT code changes. The token is read server-side
|
| 536 |
+
# only and NEVER sent to the browser. sovereign:true is asserted ONLY when that
|
| 537 |
+
# endpoint actually answers — a configured-but-dead URL never inflates the label.
|
| 538 |
# Open-weight roster only — no closed (GPT/Claude/Gemini) models.
|
| 539 |
# ---------------------------------------------------------------------------
|
| 540 |
+
_MODEL_BASE_URL = (os.environ.get("A11OY_BRAIN_URL")
|
| 541 |
+
or os.environ.get("A11OY_MODEL_BASE_URL")
|
| 542 |
or os.environ.get("HF_ROUTER_BASE")
|
| 543 |
or "https://router.huggingface.co/v1").rstrip("/")
|
| 544 |
|
a11oy_code_orchestrator.py
CHANGED
|
@@ -118,9 +118,28 @@ except Exception: # pragma: no cover - absent until the module merges; degrade
|
|
| 118 |
|
| 119 |
HF_ROUTER_BASE = os.environ.get("HF_ROUTER_BASE", "https://router.huggingface.co/v1")
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# Honest backend classification for /healthz. The agent runs on our own GPU when
|
| 122 |
-
# A11OY_MODEL_BASE_URL points at a NON-router endpoint (
|
| 123 |
-
# matching a11oy_code_engine.py's adapter. Never claims
|
|
|
|
| 124 |
def _local_endpoint_reachable(base: str, timeout: float = 2.0) -> bool:
|
| 125 |
"""Quick liveness probe of a configured local/sovereign model endpoint.
|
| 126 |
|
|
@@ -144,7 +163,7 @@ def _local_endpoint_reachable(base: str, timeout: float = 2.0) -> bool:
|
|
| 144 |
|
| 145 |
|
| 146 |
def _sovereign_inference_state() -> dict:
|
| 147 |
-
base = (
|
| 148 |
or "https://router.huggingface.co/v1").rstrip("/")
|
| 149 |
gpu = (os.environ.get("A11OY_GPU_LABEL") or "").strip()
|
| 150 |
is_local = "router.huggingface.co" not in base
|
|
@@ -186,7 +205,7 @@ def _serving_base() -> tuple[str, bool]:
|
|
| 186 |
unreachable (e.g. an HF Space with no GPU, or a tailnet endpoint this process
|
| 187 |
can't reach) we honestly fall back to the router AND report sovereign:false.
|
| 188 |
"""
|
| 189 |
-
base = (
|
| 190 |
if base and "router.huggingface.co" not in base and _local_endpoint_reachable(base):
|
| 191 |
return base, True
|
| 192 |
return HF_ROUTER_BASE, False
|
|
@@ -249,9 +268,11 @@ def _serving_base_selftest() -> dict:
|
|
| 249 |
step. Returns a dict of results; raises AssertionError on any mismatch.
|
| 250 |
"""
|
| 251 |
saved = os.environ.get("A11OY_MODEL_BASE_URL")
|
|
|
|
| 252 |
out = {}
|
| 253 |
try:
|
| 254 |
os.environ.pop("A11OY_MODEL_BASE_URL", None)
|
|
|
|
| 255 |
b0, l0 = _serving_base()
|
| 256 |
assert (b0, l0) == (HF_ROUTER_BASE, False), f"unset path: {(b0, l0)}"
|
| 257 |
out["unset"] = [b0, l0]
|
|
@@ -283,6 +304,10 @@ def _serving_base_selftest() -> dict:
|
|
| 283 |
os.environ.pop("A11OY_MODEL_BASE_URL", None)
|
| 284 |
else:
|
| 285 |
os.environ["A11OY_MODEL_BASE_URL"] = saved
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
return out
|
| 287 |
|
| 288 |
|
|
|
|
| 118 |
|
| 119 |
HF_ROUTER_BASE = os.environ.get("HF_ROUTER_BASE", "https://router.huggingface.co/v1")
|
| 120 |
|
| 121 |
+
|
| 122 |
+
def _sovereign_base_url() -> str:
|
| 123 |
+
"""Resolve the configured sovereign/local OpenAI-compatible base URL.
|
| 124 |
+
|
| 125 |
+
A11OY_BRAIN_URL is the canonical primary knob for pointing a11oy Code at an
|
| 126 |
+
owned sovereign node (szl-router / on-box SGLang/vLLM, see
|
| 127 |
+
docs SOVEREIGN_BRAIN_RUNBOOK). A11OY_MODEL_BASE_URL is kept as an accepted
|
| 128 |
+
alias for backwards compatibility. Read at runtime (env-flip law). Returns ""
|
| 129 |
+
when neither is set, so callers transparently fall back to the HF Router.
|
| 130 |
+
|
| 131 |
+
HONESTY: this returns CONFIGURED INTENT only. sovereign:true is asserted
|
| 132 |
+
elsewhere ONLY after _local_endpoint_reachable() confirms the node answers —
|
| 133 |
+
a set-but-unreachable brain URL never inflates the posture.
|
| 134 |
+
"""
|
| 135 |
+
return (os.environ.get("A11OY_BRAIN_URL")
|
| 136 |
+
or os.environ.get("A11OY_MODEL_BASE_URL") or "").strip()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
# Honest backend classification for /healthz. The agent runs on our own GPU when
|
| 140 |
+
# A11OY_BRAIN_URL/A11OY_MODEL_BASE_URL points at a NON-router endpoint (sovereign
|
| 141 |
+
# node via SGLang/vLLM), matching a11oy_code_engine.py's adapter. Never claims
|
| 142 |
+
# sovereign while still routing.
|
| 143 |
def _local_endpoint_reachable(base: str, timeout: float = 2.0) -> bool:
|
| 144 |
"""Quick liveness probe of a configured local/sovereign model endpoint.
|
| 145 |
|
|
|
|
| 163 |
|
| 164 |
|
| 165 |
def _sovereign_inference_state() -> dict:
|
| 166 |
+
base = (_sovereign_base_url() or os.environ.get("HF_ROUTER_BASE")
|
| 167 |
or "https://router.huggingface.co/v1").rstrip("/")
|
| 168 |
gpu = (os.environ.get("A11OY_GPU_LABEL") or "").strip()
|
| 169 |
is_local = "router.huggingface.co" not in base
|
|
|
|
| 205 |
unreachable (e.g. an HF Space with no GPU, or a tailnet endpoint this process
|
| 206 |
can't reach) we honestly fall back to the router AND report sovereign:false.
|
| 207 |
"""
|
| 208 |
+
base = _sovereign_base_url().rstrip("/")
|
| 209 |
if base and "router.huggingface.co" not in base and _local_endpoint_reachable(base):
|
| 210 |
return base, True
|
| 211 |
return HF_ROUTER_BASE, False
|
|
|
|
| 268 |
step. Returns a dict of results; raises AssertionError on any mismatch.
|
| 269 |
"""
|
| 270 |
saved = os.environ.get("A11OY_MODEL_BASE_URL")
|
| 271 |
+
saved_brain = os.environ.get("A11OY_BRAIN_URL")
|
| 272 |
out = {}
|
| 273 |
try:
|
| 274 |
os.environ.pop("A11OY_MODEL_BASE_URL", None)
|
| 275 |
+
os.environ.pop("A11OY_BRAIN_URL", None) # hermetic: alias must not leak in
|
| 276 |
b0, l0 = _serving_base()
|
| 277 |
assert (b0, l0) == (HF_ROUTER_BASE, False), f"unset path: {(b0, l0)}"
|
| 278 |
out["unset"] = [b0, l0]
|
|
|
|
| 304 |
os.environ.pop("A11OY_MODEL_BASE_URL", None)
|
| 305 |
else:
|
| 306 |
os.environ["A11OY_MODEL_BASE_URL"] = saved
|
| 307 |
+
if saved_brain is None:
|
| 308 |
+
os.environ.pop("A11OY_BRAIN_URL", None)
|
| 309 |
+
else:
|
| 310 |
+
os.environ["A11OY_BRAIN_URL"] = saved_brain
|
| 311 |
return out
|
| 312 |
|
| 313 |
|