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.

docs(http-api): strict JEV answers carry `type`, the pages did not say so

Aashish5dc7b742b2f8
diff --git a/docs/http-api.md b/docs/http-api.md
index 31ce234b..bc6b580a 100644
--- a/docs/http-api.md
+++ b/docs/http-api.md
@@ -258,9 +258,9 @@ rejects the full payload, so `LAYA_JEV_STRICT=1` projects the response onto the
answering, on both `/v1/systemone` and `/v1/systemone/batch`:
- the root keeps `model`, `answers` and `usage` only; `routing` is not sent;
-- a `choice` answer keeps `choice`, `probabilities` and `confidence`;
-- a `score` answer keeps `score`, `probabilities`, `confidence` and `legend`;
-- a `noul` answer keeps `noul` only;
+- a `choice` answer keeps `type`, `choice`, `probabilities` and `confidence`;
+- a `score` answer keeps `type`, `score`, `probabilities`, `confidence` and `legend`;
+- a `noul` answer keeps `type` and `noul`;
- `usage` keeps `input_tokens` and `output_tokens`; the truncation facts and the collapsed-
options ceiling are not sent.
diff --git a/laya/serve.py b/laya/serve.py
index f5a432c5..cde2ee09 100644
--- a/laya/serve.py
+++ b/laya/serve.py
@@ -163,10 +163,10 @@ def _project_jev_strict(result: Dict[str, Any]) -> Dict[str, Any]:
"""Project a result onto the strict Jev wire contract (`LAYA_JEV_STRICT`).
The Jev `/v1/systemone` response defines exactly three top-level fields
- (`model`, `answers`, `usage`), and each answer carries only its type's fields:
- choice = `choice` + `probabilities` + `confidence`, score = `score` +
- `probabilities` + `confidence` + `legend`, noul = `noul` only, and `usage` the
- two token counts. Laya's full payload adds more: a root `routing` report, a
+ (`model`, `answers`, `usage`), and each answer carries its discriminator plus its type's
+ fields: choice = `type` + `choice` + `probabilities` + `confidence`, score = `type` +
+ `score` + `probabilities` + `confidence` + `legend`, noul = `type` + `noul`, and `usage`
+ the two token counts. Laya's full payload adds more: a root `routing` report, a
per-answer `action` head plus the calibrated `answer_confidence`, a
`confidence` on noul answers, and a usage report extended with the truncation
facts and the collapsed-options ceiling. Those additions are what a client
diff --git a/tests/test_serve.py b/tests/test_serve.py
index 016703cd..f50bedc0 100644
--- a/tests/test_serve.py
+++ b/tests/test_serve.py
@@ -3288,3 +3288,63 @@ def test_idle_unload_retries_failure_and_stops_at_shutdown(monkeypatch):
router.loaded = ["english"]
router.unloaded.clear()
assert not router.unloaded.wait(0.15)
+
+
+def test_jev_strict_projection_page_names_the_projected_keys():
+ """docs/http-api.md's four strict bullets must be the key sets `_project_jev_strict` returns.
+
+ The page is the second copy of the contract, after the handler's docstring. Both used to
+ claim ``noul = `noul` only``, but the projection emits ``{"type": "noul", "noul": ...}``,
+ and the pre-existing ``test_jev_strict_projects_the_full_payload`` asserts that two-key
+ shape verbatim -- so the prose and the pinned test disagreed, and a client that validated
+ the "no fields other than `noul`" sentence rejected every strict noul answer the flag
+ exists to sanitize.
+
+ The gate calls the real projection on a fixture that carries all three answer types plus
+ the additions a strict client must not see, then reads the four bullet lines from
+ `docs/http-api.md` and asserts each bullet's backticked key set equals the corresponding
+ projected key set. The pre-fix wording is banned as a direct substring so the gate fails
+ if the page reverts.
+ """
+ import re
+ from pathlib import Path
+
+ from laya.serve import _project_jev_strict
+
+ fixture = {
+ "model": "laya-rl-agent",
+ "answers": {
+ "queue": {"type": "choice", "choice": "billing",
+ "probabilities": {"billing": 0.95, "tech": 0.05},
+ "confidence": 0.80, "action": "answer",
+ "answer_confidence": 0.75},
+ "urgency": {"type": "score", "score": 1.70, "confidence": 0.19,
+ "probabilities": {"0": 0.02, "1": 0.65, "2": 0.33},
+ "legend": {"0": "calm", "1": "firm", "2": "angry"},
+ "action": "answer"},
+ "threat": {"type": "noul", "noul": 0.9148, "confidence": 0.85,
+ "answer_confidence": 0.70, "action": "answer"},
+ },
+ "usage": {"input_tokens": 83, "output_tokens": 0,
+ "windows": 1, "collapsed_options": 0},
+ "routing": {"model": "typed-decisions", "reason": "typed workflow"},
+ }
+ projected = _project_jev_strict(fixture)
+
+ page = (Path(__file__).resolve().parents[1] / "docs" / "http-api.md").read_text(encoding="utf-8")
+
+ def bullet_keys(label):
+ for line in page.splitlines():
+ if line.startswith("- a `%s` answer keeps" % label):
+ back = line.split("keeps", 1)[1]
+ return set(re.findall(r"`([A-Za-z_][A-Za-z_0-9]*)`", back))
+ raise AssertionError("bullet for %r not found" % label)
+
+ assert set(projected["answers"]["queue"]) == bullet_keys("choice"), \
+ "doc says %r, handler emits %r" % (sorted(bullet_keys("choice")),
+ sorted(projected["answers"]["queue"]))
+ assert set(projected["answers"]["urgency"]) == bullet_keys("score")
+ assert set(projected["answers"]["threat"]) == bullet_keys("noul")
+
+ # The noul bullet must not shrink the discriminator away.
+ assert "noul only" not in page, "pre-fix 'noul only' wording is still on the page"