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(ts): a blank explicit lang falls through to detection like Python
thejenilsoni9497f5646d9f
diff --git a/laya-ts/src/router.ts b/laya-ts/src/router.tsindex b98941ba..64c6552d 100644--- a/laya-ts/src/router.ts+++ b/laya-ts/src/router.ts@@ -362,8 +362,12 @@ export class Router extends HookRegistry {};}- if (lang !== null && lang !== undefined) {- const key: ModelName = englishFromCode(lang) ? "english" : "multilingual";+ // An explicit `lang` is decisive only when the code names a language. Blank or whitespace+ // resolves to no usable hint, so it falls through to langGuess/detection exactly as an+ // abstaining hint does (Python parity); real English/non-English codes still route now.+ const resolvedLang = englishFromCode(lang);+ if (resolvedLang !== null) {+ const key: ModelName = resolvedLang ? "english" : "multilingual";return {model: key,repo: repoStr(this.models[key]),diff --git a/laya-ts/tests/blank-lang-routing.test.ts b/laya-ts/tests/blank-lang-routing.test.tsnew file mode 100644index 00000000..7a6c2508--- /dev/null+++ b/laya-ts/tests/blank-lang-routing.test.ts@@ -0,0 +1,54 @@+import { describe, expect, it } from "vitest";+import { Router } from "../src/router.js";++// Parity with tests/test_blank_lang_routing.py: a blank or whitespace explicit `lang` names no+// language, so it must fall through to langGuess/detection instead of pinning multilingual.+const GENERIC = { intent: { type: "choice", instructions: "x", criteria: ["a", "b"] } };+// Detected as English, so "abstain" (english) and "forced multilingual" are distinguishable.+const ENGLISH = "I was charged twice for invoice 4411";+const GERMAN = "Mein Konto wurde zweimal belastet, bitte erstatten Sie";++describe("blank explicit lang", () => {+ const r = new Router();++ it("baseline: plain English routes english with no explicit reason", () => {+ const d = r.route(ENGLISH, GENERIC);+ expect(d.model).toBe("english");+ expect(d.reason).not.toContain("explicit lang=");+ });++ for (const lang of ["", " ", null, undefined]) {+ it(`lang=${JSON.stringify(lang)} falls through to detection`, () => {+ const d = r.route(ENGLISH, GENERIC, { lang: lang as string | null });+ expect(d.model).toBe("english");+ expect(d.reason).not.toContain("explicit lang=");+ expect(d.detection).not.toBeNull();+ });+ }++ it("real codes still win", () => {+ expect(r.route(GERMAN, GENERIC, { lang: "en" }).model).toBe("english");+ expect(r.route(ENGLISH, GENERIC, { lang: "de" }).model).toBe("multilingual");+ expect(r.route(GERMAN, GENERIC, { lang: "en" }).reason).toContain("explicit lang=");+ expect(r.route(ENGLISH, GENERIC, { lang: "de" }).reason).toContain("explicit lang=");+ });++ for (const code of ["en", "EN", "en-US", "en_US", "en_US.UTF-8"]) {+ it(`code ${code} routes english`, () => {+ expect(r.route(ENGLISH, GENERIC, { lang: code }).model).toBe("english");+ });+ }++ for (const code of ["de", "fr", "zh_CN", "pt-BR"]) {+ it(`code ${code} routes multilingual`, () => {+ expect(r.route(ENGLISH, GENERIC, { lang: code }).model).toBe("multilingual");+ });+ }++ it("a blank lang does not mask an installed langGuess", () => {+ const hinted = new Router({ langGuess: "de" });+ const d = hinted.route(ENGLISH, GENERIC, { lang: "" });+ expect(d.model).toBe("multilingual");+ expect(d.reason).toContain("Router(lang_guess=...)");+ });+});