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(laya-ts): forward a detected "en" so lang_temperatures.en applies
thread3dc9669c93086d
diff --git a/laya-ts/src/router.ts b/laya-ts/src/router.tsindex 68d4e2b3..7799aaab 100644--- a/laya-ts/src/router.ts+++ b/laya-ts/src/router.ts@@ -639,13 +639,13 @@ export class Router extends HookRegistry {checkQuestion(qid, qdef);}// Python parity (router.py predict): the request's language also shapes the answer- // distribution through the agent's lang_temperatures. An explicit lang wins;- // otherwise forward the language the router detected for the routing decision.- // TS analyse() names English "en" where Python's analyse returns None (it only- // ever names non-English), so a detected "en" forwards as null — in Python only an- // explicit lang="en" can select an "en" override.+ // distribution through the agent's lang_temperatures. An explicit lang wins; otherwise+ // forward the language the router detected for the routing decision, "en" included --+ // Python's `analyse` names English "en" too (laya/lang.py, `_latin_profile`), and+ // `lang_temperatures` may carry an "en" entry, so replacing it with null made that+ // override dead code on this path while the same agent honoured it when called directly.const detected = decision.detection?.language;- const effectiveLang = opts.lang ?? (detected && detected !== "en" ? detected : null);+ const effectiveLang = opts.lang ?? detected ?? null;const agentOpts: PredictOptions = { lang: effectiveLang };if (mc !== null) agentOpts.minConfidence = mc;markDefaultsRan(agentOpts);@@ -900,12 +900,9 @@ export class Router extends HookRegistry {continue;}// An explicit `lang` wins; otherwise forward the language the router detected for the- // routing decision. TS analyse() names English "en" where Python's returns None (it- // only ever names non-English), so a detected "en" forwards as null — in Python only- // an explicit lang="en" can select an "en" override. Same rule as `predict`.+ // routing decision, "en" included, exactly as `predict` and Python's predict_batch do.const detectedLang = decisions[i].detection?.language ?? null;- const effectiveLang =- requests[i].lang ?? (detectedLang && detectedLang !== "en" ? detectedLang : null);+ const effectiveLang = requests[i].lang ?? detectedLang;const langKey = hasLangOverrides ? effectiveLang : null;const schema = questionSchema(ctx.questions);const found = questionGroups.find(diff --git a/laya-ts/tests/lang-temperature.test.ts b/laya-ts/tests/lang-temperature.test.tsindex ed0c3721..71ed94b3 100644--- a/laya-ts/tests/lang-temperature.test.ts+++ b/laya-ts/tests/lang-temperature.test.ts@@ -190,11 +190,15 @@ describe("Router.predict lang forwarding", () => {expect(seen).toEqual([{ lang: "bn" }]);});- it("forwards null when nothing non-English was detected", async () => {+ it("forwards the detected \"en\", so a lang_temperatures.en override is applied", async () => {+ // Python parity (laya/lang.py): `analyse` names English "en", and router.py forwards+ // `decision.detection.language` without a special case, so an `en` entry in+ // `lang_temperatures` is applied there. This path replaced "en" with null, which made that+ // override dead code on the Router while the same agent honoured it when called directly.const seen: any[] = [];const r = routerRecording(seen);await r.predict("please refund my ticket", questions);- expect(seen).toEqual([{ lang: null }]);+ expect(seen).toEqual([{ lang: "en" }]);});it("an explicit lang is forwarded verbatim, even \"en\"", async () => {@@ -203,6 +207,21 @@ describe("Router.predict lang forwarding", () => {await r.predict("please refund my ticket", questions, { lang: "en" });expect(seen).toEqual([{ lang: "en" }]);});++ it("an \"en\" override changes the answer through Router.predict", async () => {+ // End-to-end, not just the forwarded option: the same agent answers 0.7311 at temperature+ // 2 and 0.8808 at the base 1.0 (see the fixed logit row above), so a dropped "en" is a+ // visible difference in the reported probabilities rather than an unused option.+ const agent = new Agent({+ provider: fakeProvider(),+ lang_temperatures: { en: { temperature: [2, 2, 2] } },+ } as any);+ const r = new Router({ loader: () => agent } as any);+ const viaRouter: any = await r.predict("please refund my ticket", CHOICE);+ const direct: any = await agent.systemOne("please refund my ticket", CHOICE, { lang: "en" });+ expect(viaRouter.answers.d.probabilities.x).toBeCloseTo(0.7311, 4);+ expect(viaRouter.answers.d.probabilities.x).toBeCloseTo(direct.answers.d.probabilities.x, 10);+ });});describe("Router.predictBatch lang forwarding", () => {@@ -242,11 +261,11 @@ describe("Router.predictBatch lang forwarding", () => {expect(seen.map((c) => c.opts.lang)).toEqual(["bn"]);});- it("forwards no lang when nothing non-English was detected", async () => {+ it("forwards the detected \"en\" on the batch path too", async () => {const seen: any[] = [];const r = routerRecording(seen);await r.predictBatch([req("please refund my ticket")]);- expect(seen.map((c) => c.opts.lang)).toEqual([undefined]);+ expect(seen.map((c) => c.opts.lang)).toEqual(["en"]);});it("does not share a forward pass across languages", async () => {