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.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(serve): refuse unpublished path-like model ids instead of auto-routing (#919)
Cursor Agent285532874980
diff --git a/README.md b/README.mdindex 19375969..9c701422 100644--- a/README.md+++ b/README.md@@ -710,8 +710,11 @@ reachable on demand, or the server rebuilds one every time routing switches),`LAYA_IDLE_UNLOAD_SECONDS` (unload idle checkpoints; `0` disables it, `300` frees device memoryafter five minutes and makes the next request pay a cold load), and `LAYA_API_KEY` (when set, clients mustsend `Authorization: Bearer <key>`). A client's `model` field is honoured when it-names a Laya checkpoint (`english`/`multilingual`/`typed-decisions`), otherwise-the router auto-selects by script/language. The same body can also carry `task`,+names a Laya checkpoint (`english`/`multilingual`/`typed-decisions` or a published Hub id).+`jev-1` and `convaiinnovations/laya` still mean the router auto-selects by script/language.+A path or an unpublished Hub id (`/path/to/checkpoint`, `org/repo`) is a 422 on both+`/v1/systemone` and `/v1/systemone/batch` instead of being answered by another checkpoint.+The same body can also carry `task`,`lang`, `lang_guess`, `min_confidence`, `max_len` and `head_max_len` — the controls`Router.predict` takes that a JSON body can state — while the five hook arguments(`hooks`, `on_predict_start`, `on_predict_end`, `hooks_raise`, `hooks_timeout`) are refuseddiff --git a/docs/http-api.md b/docs/http-api.mdindex f9442f07..31ce234b 100644--- a/docs/http-api.md+++ b/docs/http-api.md@@ -121,7 +121,7 @@ curl -s localhost:8000/v1/systemone -H 'content-type: application/json' -d '{|---|---|---|| `state` | yes | text, email, ticket or JSON document to decide on; a missing or `null` state is a `400` || `questions` | yes | object keyed by question id; each question is `choice` / `score` / `noul` with `instructions` and `criteria` |-| `model` | no | names a checkpoint; anything else is ignored (see below) |+| `model` | no | names a checkpoint; a path or unpublished Hub id is a `422`, anything else is ignored (see below) || `task` | no | forces a checkpoint by workflow name instead of letting routing decide; an unknown name is a `422` naming it || `lang` | no | a language code (`de`, `en-US`) that skips detection when it names a language; a blank or unrecognised code falls through to detection || `lang_guess` | no | a language code from the client's own identifier, consulted after `lang` and before detection; any non-English code routes to the multilingual checkpoint |@@ -141,9 +141,14 @@ now get the same answer.`model` is accepted so a Jev client can keep sending one. The public Hugging Face ids(`convaiinnovations/laya-multilingual`, `convaiinnovations/laya-typed-decisions`), the checkpoint-names (`english`, `multilingual`, `typed-decisions`) and their aliases select a checkpoint; any-other value -- including a Jev id like `jev-1` -- means "let the router choose", and the response's-`routing` block records what was chosen and why.+names (`english`, `multilingual`, `typed-decisions`) and their aliases select a checkpoint.+`convaiinnovations/laya`, and any other value that is not a path or a Hub repo id -- including a+Jev id like `jev-1` -- means "let the router choose", and the response's `routing` block records+what was chosen and why. A value that looks like a filesystem path or an unpublished Hub id+(`/path/to/checkpoint`, `org/repo`, `~/ckpt`, `.\ckpt`) is a `422` on both `/v1/systemone` and+`/v1/systemone/batch`: this server cannot load it, and answering with another checkpoint would+hide that. The detail is the same `unknown model` text core raises, plus the reminder to omit+`model` to let the router choose.### Responsediff --git a/laya/serve.py b/laya/serve.pyindex b259b998..f5a432c5 100644--- a/laya/serve.py+++ b/laya/serve.py@@ -212,23 +212,58 @@ def _published_model_ids() -> Dict[str, str]:return {repo: name for name, repo in STANDALONE_MODELS.items() if repo != BUNDLE_REPO}+def _names_unpublished_source(text: str) -> bool:+ """True when `text` is a filesystem path or a Hub repo id, not a checkpoint name.++ A slash or backslash is how both a path and a `org/repo` id are written. A leading+ ``.`` or ``~`` is a relative or home path with no slash yet (``./ckpt``, ``~/ckpt``).+ Checkpoint names, aliases and a Jev id such as ``jev-1`` have none of those, so they+ are not this. Published ids are matched before the caller asks.+ """+ if not text:+ return False+ if text[0] in ".~":+ return True+ return "/" in text or "\\" in text++def _resolve_model(model: Optional[str]) -> Optional[str]:- """Map a client's `model` field onto a Laya checkpoint, or None to auto-route."""+ """Map a client's `model` field onto a Laya checkpoint, or None to auto-route.++ A Jev id such as ``jev-1``, and the bundle id ``convaiinnovations/laya``, stay None:+ both mean "let the Router choose". A path or an unpublished Hub repo id is a+ different miss. Swallowing it used to answer with whichever checkpoint routing+ picked, which is a wrong answer. That request is a 422 instead.+ """if not model:return None- published = _published_model_ids().get(str(model).strip().lower())+ text = str(model).strip()+ published = _published_model_ids().get(text.lower())if published is not None:return published- from .router import normalise_name+ from .router import BUNDLE_REPO, normalise_name+ # The root bundle is the one Hub id whose documented meaning is auto-route, not a pin.+ # It contains a slash, so the path check below would otherwise refuse it.+ if text.lower() == BUNDLE_REPO:+ return None# normalise_name raises ValueError on anything that is not a known checkpoint# or alias, and returns a name from router.DEFAULT_MODELS when it does accept one --# so it is the only list of accepted names this needs. A Jev client's `model` field# (e.g. "jev-1") is expected to miss; treat that as "no explicit checkpoint" and let- # the router auto-select.+ # the router auto-select. A path or unpublished Hub id is not that miss: the caller+ # named a checkpoint this server cannot load, the same refusal `validate_model` gives+ # an MCP client, reported as this endpoint's 422.try:return normalise_name(model)- except Exception:+ except ValueError as error:+ if _names_unpublished_source(text):+ from fastapi import HTTPException++ raise HTTPException(+ status_code=422,+ detail="%s, or omit model to let the router choose" % error,+ ) from Nonereturn Nonediff --git a/sdk/typescript/README.md b/sdk/typescript/README.mdindex 1369a23c..32ed6cba 100644--- a/sdk/typescript/README.md+++ b/sdk/typescript/README.md@@ -164,7 +164,7 @@ reference, and this client exposes them as options on `predict()`:| option | wire field | meaning ||---|---|---|-| `model` | `model` | checkpoint name or alias for this request |+| `model` | `model` | checkpoint name or alias for this request; a path or unpublished Hub id is a 422 from the server || `task` | `task` | force a workflow; an unknown name is a 422 naming it || `lang` | `lang` | a language code that skips detection when it names a language || `langGuess` | `lang_guess` | a code from your own LID, consulted before detection |diff --git a/tests/test_serve.py b/tests/test_serve.pyindex 08d2a6ec..016703cd 100644--- a/tests/test_serve.py+++ b/tests/test_serve.py@@ -575,6 +575,65 @@ def test_resolve_model_follows_the_router_registry(monkeypatch):assert _resolve_model("jev-1") is None+def test_path_or_unpublished_hub_id_is_refused_on_both_endpoints(monkeypatch):+ """A path or Hub id this server cannot load must not be answered by another checkpoint.++ ``jev-1`` and ``convaiinnovations/laya`` stay "let the router choose", and so does a+ plain unknown name: only a path or an unpublished repo id is a wrong answer (#919).+ Both ``/v1/systemone`` and ``/v1/systemone/batch`` resolve ``model`` through the same+ helper, so a miss has to be a 422 on each, before any inference.+ """+ from fastapi import HTTPException++ passthrough = ("jev-1", "JEV-1", "convaiinnovations/laya", "Convaiinnovations/Laya",+ " convaiinnovations/laya ", "not-a-checkpoint", None, "")+ for kept in passthrough:+ assert _resolve_model(kept) is None, kept++ refused = (+ "/path/to/checkpoint",+ " /path/to/checkpoint ",+ "org/repo",+ "someone/my-checkpoint",+ "~/models/ckpt",+ "./checkpoint",+ ".\\checkpoint",+ "C:\\models\\ckpt",+ )+ for raw in refused:+ with pytest.raises(HTTPException) as caught:+ _resolve_model(raw)+ err = caught.value+ assert err.status_code == 422, raw+ assert "unknown model" in err.detail, err.detail+ assert "choose one of" in err.detail, err.detail+ assert "omit model to let the router choose" in err.detail, err.detail+ assert repr(raw) in err.detail, err.detail++ client, fake = _client(monkeypatch)+ questions = REQ["questions"]+ for raw in ("/path/to/checkpoint", "org/repo", "~/models/ckpt", ".\\checkpoint"):+ single = client.post("/v1/systemone", json={**REQ, "model": raw})+ assert single.status_code == 422, (raw, single.text)+ assert "unknown model" in single.json()["detail"]+ assert repr(raw) in single.json()["detail"]+ batch = client.post("/v1/systemone/batch", json={+ "states": ["one", "two"], "questions": questions, "model": raw})+ assert batch.status_code == 422, (raw, batch.text)+ assert "unknown model" in batch.json()["detail"]+ assert repr(raw) in batch.json()["detail"]+ assert fake.calls == [], fake.calls++ for kept in ("jev-1", "convaiinnovations/laya", "not-a-checkpoint"):+ single = client.post("/v1/systemone", json={**REQ, "model": kept})+ assert single.status_code == 200, (kept, single.text)+ assert fake.calls[-1]["model"] is None, (kept, fake.calls[-1])+ batch = client.post("/v1/systemone/batch", json={+ "states": ["one"], "questions": questions, "model": kept})+ assert batch.status_code == 200, (kept, batch.text)+ assert fake.calls[-1]["model"] is None, (kept, fake.calls[-1])++def test_thread_limit(monkeypatch):pytest.importorskip("torch")monkeypatch.delenv("LAYA_THREADS", raising=False)