Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(serve): declare predict_batch hook refusals, doc types, and health test hygiene (#909)

Swatantra Yadav4506d394b7f0
diff --git a/laya/router.py b/laya/router.py
index c70896f8..b51ea42f 100644
--- a/laya/router.py
+++ b/laya/router.py
@@ -1185,7 +1185,7 @@ class Router(HookRegistry):
``questions``.
hooks_timeout: Override the Router's ``hooks_timeout`` for this call, applied to
every request's ``on_route`` dispatch, as on :meth:`route`.
- hooks: Per-call hook or sequence of hooks for this call.
+ hooks (HookArg): Per-call hook or sequence of hooks for this call.
hooks_raise: Override the Router's ``hooks_raise`` policy for this call.
"""
if not isinstance(requests, SequenceABC) or isinstance(requests, (str, bytes)):
@@ -1267,15 +1267,15 @@ class Router(HookRegistry):
``lang_guess`` routing overrides and ``max_len`` / ``head_max_len`` token-budget
overrides.
batch_size: Optional maximum number of states per Agent forward-pass batch.
- hooks_timeout: Override the Router's ``hooks_timeout`` for this call.
min_confidence: Optional float or per-bucket mapping for confidence gating.
sort_by_length: Forwarded to every ``Agent.predict_batch`` call, so each question
group pads to a shorter maximum; see ``Agent.predict_batch``. Results retain the
input order either way. Silently dropped for an attached agent whose
``predict_batch`` predates the knob (#294).
- hooks: Per-call hook or sequence of hooks for this call.
- on_predict_start: Plain callable or sequence of callables for start events.
- on_predict_end: Plain callable or sequence of callables for end events.
+ hooks_timeout: Override the Router's ``hooks_timeout`` for this call.
+ hooks (HookArg): Per-call hook or sequence of hooks for this call.
+ on_predict_start (PredictHookArg): Plain callable or sequence of callables for start events.
+ on_predict_end (PredictHookArg): Plain callable or sequence of callables for end events.
hooks_raise: Override the Router's ``hooks_raise`` policy for this call.
Returns:
diff --git a/tests/test_serve.py b/tests/test_serve.py
index 075e370e..08d2a6ec 100644
--- a/tests/test_serve.py
+++ b/tests/test_serve.py
@@ -2419,7 +2419,7 @@ def test_batch_call_controls_are_exactly_predict_batch_kwargs_or_refusal():
from laya.router import Router
taken = set(inspect.signature(Router.predict_batch).parameters) - {"self", "requests"}
- declared = set(BATCH_BODY_CALL_CONTROLS) | {"hooks_timeout"}
+ declared = set(BATCH_BODY_CALL_CONTROLS) | set(BODY_REFUSALS)
assert taken == declared, "predict_batch() takes %s; serve declares %s" % (
sorted(taken), sorted(declared))
@@ -2682,10 +2682,12 @@ def test_health_liveness_is_open_but_the_detail_needs_the_bearer(monkeypatch):
assert leaked not in anonymous.json()
-def test_health_without_an_api_key_is_unchanged():
+def test_health_without_an_api_key_is_unchanged(monkeypatch):
"""A deployment that set no key never asked to be gated, so it gets the whole payload."""
from fastapi.testclient import TestClient
+ monkeypatch.delenv("LAYA_API_KEY", raising=False)
+ monkeypatch.delenv("LAYA_IDLE_UNLOAD_SECONDS", raising=False)
client = TestClient(create_app(router=FakeRouter()))
_, returned = _health_return_keys()
assert sorted(client.get("/health").json()) == sorted(returned)
@@ -2764,7 +2766,7 @@ def test_http_api_page_documents_exactly_the_health_fields():
"device_is_preference says %r with checkpoint_devices %r" % (
sample["device_is_preference"], sample["checkpoint_devices"]))
if sample["checkpoint_devices"]:
- assert sample["device"] == next(iter(sample["checkpoint_devices"].values())), (
+ assert sample["device"] == sample["checkpoint_devices"][sample["loaded"][0]], (
"device must be the first resident checkpoint's device, as serve.py computes it")
# And the shape of a fallback entry, which no page has ever spelled out: read from the dict the