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(shortlist): leave the round's KeyError where the cross-language fixture records it
Aashish88596fa7e1af
diff --git a/laya/shortlist.py b/laya/shortlist.pyindex 2aedb729..24614d12 100644--- a/laya/shortlist.py+++ b/laya/shortlist.py@@ -174,11 +174,10 @@ def predict_tournament(come from the final call, so a tournament choice's probabilities are over itsfinalists only.- Every call's reply is checked against the same shape, the elimination rounds included: a- reply that is not a dict, one whose ``answers`` is not a dict, and a round whose answers- leave one of the numbered group questions out each raise that contract by name. The group- numbers are invented here, so an unanswered group would otherwise surface as a ``KeyError``- on a question id no request contains.+ Every call's reply is checked against the same shape, the elimination rounds included: a reply+ that is not a dict, and one whose ``answers`` is not a dict, each raise that contract by name+ instead of an indexing error or a bare ``KeyError`` from inside the module. What an answer holds+ is not checked: the final call's answers go to the caller as the agent wrote them.Extra keyword arguments are forwarded to every call (for example ``model=`` on a ``Router``)."""@@ -210,8 +209,7 @@ def predict_tournament(if not groups:breakround_questions = {str(i): cut(qid, labels) for i, (qid, labels) in enumerate(groups)}- answers = _round_answers(_call_predict(agent, state, round_questions, **predict_kwargs),- len(groups))+ answers = _round_answers(_call_predict(agent, state, round_questions, **predict_kwargs))winners: Dict[str, List[Any]] = {}for i, (qid, _labels) in enumerate(groups):winners.setdefault(qid, []).append(answers[str(i)]["choice"])@@ -542,22 +540,20 @@ def _call_predict(agent, state, questions, **predict_kwargs):return result-def _round_answers(result, n_groups):- """The answers of one elimination round, keyed by the group numbers this module invented.+def _round_answers(result):+ """The answers mapping of one elimination round, which this module indexes by group number.- ``predict_tournament`` numbers its own group questions, so the keys it indexes here are keys- the caller never wrote. An agent that answers fewer questions than it was handed would fail on- a ``KeyError`` naming a number no request contains; the omitted ids are named instead.+ ``predict_tournament`` numbers its own group questions, so the keys it indexes here are keys the+ caller never wrote. A group a reply leaves out still raises the plain ``KeyError`` for its+ number: ``laya-java/fixtures/tournament.json`` records that as the cross-language contract, for+ the Java and TypeScript ports read the same reply, so naming it here would move three ports+ rather than one module."""answers = result.get("answers")if not isinstance(answers, dict):raise TypeError("predict/system_one must return an answers dict, got %s" % type(answers).__name__)- missing = [str(i) for i in range(n_groups) if str(i) not in answers]- if missing:- raise ValueError("the round answered %d of %d group questions, omitting %s"- % (n_groups - len(missing), n_groups, ", ".join(missing)))return answersdiff --git a/tests/test_shortlist.py b/tests/test_shortlist.pyindex 893884dd..d06f2c3f 100644--- a/tests/test_shortlist.py+++ b/tests/test_shortlist.py@@ -973,10 +973,9 @@ check_raises("tournament/choice without criteria",# --------------------------------------------- every call's reply is held to the same contract# `predict_shortlist` and the tournament's final call both refused a non-dict reply by naming that-# contract; the tournament's round call indexed the reply instead. The same agent fault therefore-# raised Python's indexing error from inside the module, and a reply that skipped one of the-# numbered group questions raised a `KeyError` on an id no request contains -- the groups are-# numbered here, so the caller has nothing to match that number against.+# contract; the tournament's round call indexed the reply instead, so the same agent fault raised+# Python's indexing error from inside the module. These checks hold the shape guards that close+# that gap, and pin the bare `KeyError`s the narrowing deliberately leaves where they are.class Reply:"""Answers every call with ``shape``, so only the reply's shape varies between these stubs.@@ -1037,9 +1036,18 @@ check("shortlist/reply must be a dict, said by name", _message(check("tournament/round reply without an answers mapping is named too",_message(_round({"model": "fake"})),"TypeError: predict/system_one must return an answers dict, got NoneType")-check("tournament/a round that leaves groups out names the omitted ones",+# What is deliberately not changed: an answer this module indexes is still looked up directly, so a+# round that skips a group raises the bare `KeyError` for that group's number, and an answer with no+# choice raises `KeyError: 'choice'`. `laya-java/fixtures/tournament.json` records both messages as+# the contract the Java and TypeScript ports are tested against, so naming them here would move+# three ports and their committed fixtures rather than one module.+check("tournament/a round that leaves groups out keeps the bare KeyError",_message(_round(lambda q: {"model": "fake", "answers": {"0": {"choice": "l00"}}})),- "ValueError: the round answered 1 of 5 group questions, omitting 1, 2, 3, 4")+ "KeyError: '1'")+check("tournament/an answer with no choice keeps the bare KeyError",+ _message(_round(lambda q: {"model": "fake",+ "answers": {qid: {"score": 1.0} for qid in q}})),+ "KeyError: 'choice'")# Each call site is guarded on its own: an agent can answer the caller's request and hand back a# list for the invented groups, or the other way round. Either way the round has already run, so a# guard only on the last call would not catch the first of these.