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)!: match the multilingual routing default
Rishit Sharmacda0216bfcfc
diff --git a/laya-ts/README.md b/laya-ts/README.mdindex 2a7b0bb3..c13c585a 100644--- a/laya-ts/README.md+++ b/laya-ts/README.md@@ -16,7 +16,7 @@ python laya-ts/scripts/export_onnx.py --model-dir <ckpt> --out-dir ./modelimport { Agent, Router } from "laya-ts";const agent = await Agent.load("./model"); // local dir, or ("convaiinnovations/laya", { subfolder: "multilingual" })-const router = new Router();+const router = new Router({ default: "english" }); // this example attaches only the English checkpointrouter.attach("english", agent);const out = await router.predict({ body: "charged twice, refund please" }, {intent: { type: "choice", instructions: "What does the customer want?", criteria: { refund: "money back", other: "anything else" } },@@ -26,6 +26,12 @@ console.log(out.answers.intent);CUDA: `Agent.load("./model", { device: "cuda" })` (falls back to CPU with a warning).+`new Router()` uses the multilingual checkpoint for text whose language the detector cannot+identify, including text with no letters, matching Python 0.4.0. Identified English still routes+to the English checkpoint, and detected non-Latin scripts route to multilingual. Set+`new Router({ default: "english" })` to restore the earlier fallback; explicit `model` and `lang`+options still take precedence.+## Browser (WebGPU → WASM fallback)```tsdiff --git a/laya-ts/src/router.ts b/laya-ts/src/router.tsindex 8ecc0c01..6a11f9cd 100644--- a/laya-ts/src/router.ts+++ b/laya-ts/src/router.ts@@ -121,6 +121,7 @@ export interface RouterOptions {token?: string | null;maxLoaded?: number;max_loaded?: number;+ /** Fallback for unidentified text. Defaults to "multilingual", matching Python 0.4.0. */default?: string;autoTaskDetection?: boolean;auto_task_detection?: boolean;@@ -302,7 +303,7 @@ export class Router extends HookRegistry {}}this.maxLoaded = Math.max(1, Math.trunc(Number(opts.maxLoaded ?? opts.max_loaded ?? 2)));- this.default = normaliseName(opts.default ?? "english");+ this.default = normaliseName(opts.default ?? "multilingual");this.autoTaskDetection = Boolean(opts.autoTaskDetection ?? opts.auto_task_detection ?? false);this.langGuess = opts.langGuess ?? opts.lang_guess ?? null;this.loader = opts.loader ?? null;diff --git a/laya-ts/tests/hooks.test.ts b/laya-ts/tests/hooks.test.tsindex 399af981..75eb5d7a 100644--- a/laya-ts/tests/hooks.test.ts+++ b/laya-ts/tests/hooks.test.ts@@ -43,7 +43,7 @@ function makeRouter(extra: Record<string, unknown> = {}) {return { model: "laya-rl-agent", answers: {}, usage: { input_tokens: 5, output_tokens: 0 } };},});- const router = new Router({ loader, ...extra } as never);+ const router = new Router({ default: "english", loader, ...extra } as never);return { router, calls };}diff --git a/laya-ts/tests/router-batch.test.ts b/laya-ts/tests/router-batch.test.tsindex 8407d0eb..e8b2ae7f 100644--- a/laya-ts/tests/router-batch.test.ts+++ b/laya-ts/tests/router-batch.test.ts@@ -37,7 +37,7 @@ const makeRouter = (opts: Record<string, unknown> = {}) => {},};};- const router = new Router({ loader: loader as never, ...opts });+ const router = new Router({ default: "english", loader: loader as never, ...opts });return { router, built, calls };};diff --git a/laya-ts/tests/router.test.ts b/laya-ts/tests/router.test.tsindex 54e9593d..f5623b48 100644--- a/laya-ts/tests/router.test.ts+++ b/laya-ts/tests/router.test.ts@@ -3,6 +3,44 @@ import { Router, normaliseName } from "../src/router.js";describe("router", () => {it("normalises aliases", () => { expect(normaliseName("en")).toBe("english"); });it("rejects unknown model", () => { expect(() => normaliseName("jev-1")).toThrow(); });+ it.each(["refund", "12345 ???", { body: "refund" }])("uses multilingual for unidentified state %j", (state) => {+ const r = new Router();+ const decision = r.route(state, {});+ expect(r.default).toBe("multilingual");+ expect(decision.detection?.languageUndecided).toBe(true);+ expect(decision.model).toBe("multilingual");+ expect(decision.reason).toContain("using default (multilingual)");+ expect(r.loaded).toEqual([]);+ });+ it.each(["english", "multilingual"])("applies default %s only to unidentified text", (fallback) => {+ const r = new Router({ default: fallback });+ expect(r.route("refund", {}).model).toBe(fallback);+ expect(r.route("Please refund the duplicate charge on the invoice", {}).model).toBe("english");+ expect(r.route("मुझसे दो बार शुल्क लिया गया", {}).model).toBe("multilingual");+ expect(r.route("refund", {}, { lang: "en" }).model).toBe("english");+ expect(r.route("refund", {}, { model: "typed-decisions" }).model).toBe("typed-decisions");+ });+ it("uses the default in a mixed routing batch", () => {+ const r = new Router();+ const decisions = r.routeBatch([+ { state: "refund", questions: {} },+ { state: "Please refund the duplicate charge on the invoice", questions: {} },+ ]);+ expect(decisions.map((d) => d.model)).toEqual(["multilingual", "english"]);+ expect(r.loaded).toEqual([]);+ });+ it("loads the multilingual checkpoint when predicting unidentified text", async () => {+ const loader = vi.fn(async () => ({+ async systemOne() {+ return { model: "laya-rl-agent", answers: {}, usage: { input_tokens: 5, output_tokens: 0 } };+ },+ }));+ const r = new Router({ loader });+ const result = await r.predict("refund", { q: { type: "noul", instructions: "?" } });+ expect(loader).toHaveBeenCalledWith("multilingual", r.models.multilingual);+ expect(result.routing.model).toBe("multilingual");+ expect(r.loaded).toEqual(["multilingual"]);+ });it("routes hindi script to multilingual without loading", () => {const r = new Router();expect(r.route({ body: "मुझसे दो बार शुल्क लिया गया" }, {}).model).toBe("multilingual");diff --git a/tests/test_hooks_api.py b/tests/test_hooks_api.pyindex 2f5b200a..1214c2df 100644--- a/tests/test_hooks_api.py+++ b/tests/test_hooks_api.py@@ -80,6 +80,8 @@ for label, fn in (("Agent.__init__", Agent.__init__), ("load", load)):check_param(label, fn, "compile_cache", False)check_param(label, fn, "compile_mode", "default")+# Python and TypeScript share the 0.4.0 fallback for unidentified text.+check_param("Router.__init__", Router.__init__, "default", "multilingual")# Router keeps lang_guess and explicit per-model revisions toocheck_param("Router.__init__", Router.__init__, "lang_guess", None)check_param("Router.__init__", Router.__init__, "revisions", None)