Skip to content

armgit / laya

Public Imported from GitHub
0

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.

fix(ts): accept a null or undefined noul `labels` as the defaults, as Python does

divit aggarwal14ddedd00e29
diff --git a/laya-ts/src/agent.ts b/laya-ts/src/agent.ts
index f5bc8e69..f20d29c7 100644
--- a/laya-ts/src/agent.ts
+++ b/laya-ts/src/agent.ts
@@ -187,7 +187,7 @@ export function checkQuestion(qid: string, qdef: unknown): void {
if ("labels" in q && t !== "noul") {
throw new Error(`question ${qidStr(qid)}: 'labels' is only supported for noul questions`);
}
- if (t === "noul" && "labels" in q) {
+ if (t === "noul" && q["labels"] !== null && q["labels"] !== undefined) {
const labels = q["labels"];
if (typeof labels !== "object" || labels === null || Array.isArray(labels)) {
throw new Error(`question ${qidStr(qid)}: noul labels must be an object with 'false' and 'true'`);
diff --git a/laya-ts/tests/audit-regressions.test.ts b/laya-ts/tests/audit-regressions.test.ts
index 041cf7cb..2a743fb5 100644
--- a/laya-ts/tests/audit-regressions.test.ts
+++ b/laya-ts/tests/audit-regressions.test.ts
@@ -3,7 +3,7 @@ import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Agent, checkQuestion, toInternal } from "../src/agent.js";
-import { buildSequence } from "../src/common.js";
+import { buildSequence, renderOptions } from "../src/common.js";
import { loadNodeBundle } from "../src/providers.js";
const tokenizer = () => ({
@@ -53,6 +53,19 @@ describe("audit regressions", () => {
expect(() => checkQuestion("q", { type: "choice", instructions: "?", criteria: ["yes"], labels: { false: "No", true: "Yes" } })).toThrow("labels");
});
+ it("treats a null or undefined noul `labels` as the defaults, as Python does", () => {
+ const defaults = renderOptions(toInternal({ type: "noul", instructions: "?" }));
+ for (const labels of [null, undefined]) {
+ const q = { type: "noul", instructions: "?", labels };
+ expect(() => checkQuestion("q", q)).not.toThrow();
+ expect(renderOptions(toInternal(q))).toEqual(defaults);
+ }
+ for (const labels of ["x", [], {}, 5, { false: "No" }]) {
+ expect(() => checkQuestion("q", { type: "noul", instructions: "?", labels })).toThrow("labels");
+ }
+ expect(() => checkQuestion("q", { type: "choice", instructions: "?", criteria: ["a"], labels: null })).toThrow("labels");
+ });
+
it("rejects a null score level, as Python does (#302)", () => {
expect(() => checkQuestion("q", { type: "score", instructions: "?", criteria: ["low", null, "high"] })).toThrow("level 1");
expect(() => checkQuestion("q", { type: "score", instructions: "?", criteria: ["low", "mid", undefined] })).toThrow("level 2");