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
Merge pull request #648 from Swatantra-66/fix/ts-validate-questions-and-state
Nandakishor11bb83b16286
diff --cc laya-ts/src/agent.tsindex 2e72bb7d,50119f28..ce6af461--- a/laya-ts/src/agent.ts+++ b/laya-ts/src/agent.ts@@@ -429,12 -390,39 +435,35 @@@ export class Agent extends HookRegistrtry {await dispatchAsync(active, "onPredictStart", ctx, { raiseErrors });if (ctx.results === null) {+ if (!Array.isArray(ctx.states)) {+ throw new TypeError(+ "predictBatch expects an array of states; pass a single state to predict()/systemOne().",+ );+ }+ if (!isPlainDict(ctx.questions)) {+ const typeName =+ ctx.questions === null+ ? "NoneType"+ : Array.isArray(ctx.questions)+ ? "list"+ : typeof ctx.questions === "object"+ ? ((ctx.questions as object).constructor?.name ?? "object")+ : typeof ctx.questions;+ throw new TypeError(+ `questions must be a dict of question id -> definition, got ${typeName}`,+ );+ }+ for (const st of ctx.states) {+ if (st === null || st === undefined) {+ throw new TypeError("state must not be None; pass a string, dict, or list");+ }+ }- const out: SystemOneResult[] = [];- for (const st of ctx.states) {- out.push(- await this._systemOneCore(- st,- ctx.questions as Record<string, QuestionDef>,- opts.lang ?? null,- ),- );- }+ const out = await this._systemOneMany(ctx.states, ctx.questions as Record<string, QuestionDef>, {+ maxLen: ctx.maxLen,+ headMaxLen: ctx.headMaxLen,+ batchSize: opts.batchSize ?? null,+ lang: opts.lang ?? null,+ });ctx.results = out as unknown as Record<string, unknown>[];ctx.model ??= out[0]?.model ?? null;}diff --cc laya-ts/tests/agent.test.tsindex 583c0d01,5d9adc22..69a817be--- a/laya-ts/tests/agent.test.ts+++ b/laya-ts/tests/agent.test.ts@@@ -1,8 -1,8 +1,17 @@@import { describe, expect, it } from "vitest";import { Agent } from "../src/agent.js";const fakeProvider = () => ({-- async runEncoder(_b: any) { return { lastHidden: [[1, 0], [0, 1]] }; },-- async runHead(_h: any) { return { logits: [[2, 0, 1, 0]], act: [[3, 0]] }; },++ async runEncoder(b: any) {++ const n = b?.inputIds?.length ?? 1;++ return { lastHidden: Array.from({ length: n }, () => [[1, 0], [0, 1]]) };++ },++ async runHead(_h: any, batch?: any) {++ const n = batch?.inputIds?.length ?? 1;++ return {++ logits: Array.from({ length: n }, () => [2, 0, 1, 0]),++ act: Array.from({ length: n }, () => [3, 0]),++ };++ },});describe("agent", () => {it("empty questions skip forward pass", async () => {