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(cli): `--preset` sent the request under a key no question set names
PerryLink049b25243786
diff --git a/laya/cli.py b/laya/cli.pyindex 31cbee3b..adf16116 100644--- a/laya/cli.py+++ b/laya/cli.py@@ -27,6 +27,17 @@ PRESETS = {"triage": laya.triage_questions,}+# The state field each preset's instructions name, so the CLI puts the text where that question+# set reads it. `router` is also the default for `--predict`, which answers+# `laya.router_questions()`. Kept beside PRESETS so a new preset and its key arrive together.+PRESET_STATE_KEYS = {+ "email": "body",+ "guard": "prompt",+ "moderation": "post",+ "router": "request",+ "triage": "message",+}+def build_parser():parser = argparse.ArgumentParser(@@ -82,10 +93,17 @@ def show_answers(result):def run(text, args, router=None):"""Route or predict one request; returns 0 on success, 2 on a handled error."""router = router or make_router(args)- state = {"text": text}try:if args.predict or args.preset:questions = PRESETS[args.preset]() if args.preset else laya.router_questions()+ # Each preset's instructions name the field they read -- `` `message` ``,+ # `` `body` ``, `` `prompt` ``, `` `post` ``, `` `request` `` -- and the CLI used to+ # send every request as `{"text": ...}`, a key none of them names, so the model was+ # asked about a field that was not there. The state key therefore follows the+ # question set being answered. Routing is not affected either way: `route` reads the+ # state only for language detection, which is key-invariant, so the default path+ # keeps `{"text": ...}`.+ state = {PRESET_STATE_KEYS.get(args.preset, "request"): text}result = router.predict(state, questions,model=args.model, task=args.task, lang=args.lang)if args.json:@@ -93,6 +111,7 @@ def run(text, args, router=None):else:show_answers(result)else:+ state = {"text": text}decision = router.route(state, model=args.model, task=args.task, lang=args.lang)if args.json:print(json.dumps(dict(decision), ensure_ascii=False, indent=2, default=str))diff --git a/tests/test_cli.py b/tests/test_cli.pyindex c3c73541..a4b3262a 100644--- a/tests/test_cli.py+++ b/tests/test_cli.py@@ -89,6 +89,7 @@ class QuestionRecorder:def __init__(self):self.questions = Noneself.route_calls = []+ self.states = []def route(self, state, **kwargs):self.route_calls.append((state, kwargs))@@ -96,6 +97,7 @@ class QuestionRecorder:def predict(self, state, questions, **kwargs):self.questions = questions+ self.states.append(state)return {"answers": {"intent": {"choice": "refund", "probability": 0.9}}}@@ -116,6 +118,32 @@ check("preset: guard questions passed",sorted(stub.questions) == sorted(cli.PRESETS["guard"]()),str(sorted(stub.questions or {})))+# The state key has to be the field the question set's instructions name, or the model is asked+# about a field that is not there. Every preset names a different one, so this is per-preset and+# a single hard-coded key cannot be right for all of them. The routing path is deliberately not+# covered here: `route` reads the state only for language detection, which is key-invariant, and+# `route: state carries the text` above pins that path's `{"text": ...}`.+for preset, key in sorted(cli.PRESET_STATE_KEYS.items()):+ code, out, err, stub = run_cli(["the request", "--preset", preset], router=QuestionRecorder())+ check("preset %s: exit code" % preset, code == 0, "got %r" % code)+ check("preset %s: state carries the text under %r" % (preset, key),+ stub.states[0] == {key: "the request"},+ str(stub.states[0] if stub.states else None))++code, out, err, stub = run_cli(["--predict", "the request"], router=QuestionRecorder())+check("predict: state carries the text under 'request' (router_questions)",+ stub.states[0] == {"request": "the request"},+ str(stub.states[0] if stub.states else None))++# every preset's key must be one its own instructions actually name, so the two cannot drift+import re as _re # noqa: E402+for preset, fn in sorted(cli.PRESETS.items()):+ named = {m for q in fn().values()+ for m in _re.findall(r"`(\w+)`", q.get("instructions") or "")}+ check("preset %s: its key is one it names" % preset,+ cli.PRESET_STATE_KEYS[preset] in named, "%r not in %s" % (cli.PRESET_STATE_KEYS[preset],+ sorted(named)))+code, out, err, stub = run_cli(["--predict", "Refactor this service"], router=QuestionRecorder())check("preset: absent means router questions",sorted(stub.questions) == sorted(cli.PRESETS["router"]()),