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.

Merge PR #1398

Nandakishor508ad2e3dc6c
diff --cc tests/test_cli.py
index bd7c301c,2f88c23c..e9c9bcfc
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@@ -710,18 -733,14 +733,26 @@@ check("questions: too-deep JSON is exi
code == 2 and "nested deeper" in err and "checkpoint" not in err,
"code %r err %r" % (code, err))
+# A path that exists but is not a readable file -- here a directory -- is the same fault one step
+# further out: `open()` raises IsADirectoryError, an OSError that run()'s
+# `except (ImportError, OSError, RuntimeError)` reports as "could not run Laya" with advice to check
+# the network. It has to name the path and stay a usage error, like the three cases above.
+questions_dir = os.path.join(_TMP, "a-directory")
+os.makedirs(questions_dir, exist_ok=True)
+code, out, err, stub = run_cli(["hi", "--questions", questions_dir], router=QuestionRecorder())
+check("questions: a directory is exit 2 naming the file, not a runtime error",
+ code == 2 and "cannot be read" in err and questions_dir in err and "could not run Laya" not in err,
+ "code %r err %r" % (code, err))
+check("questions: a directory never reaches predict", stub.questions is None, str(stub.questions))
+
+ # A UTF-8 BOM is what Notepad and Excel write. The other file readers in this repo open with
+ # `utf-8-sig` for exactly that reason (docker/entrypoint.py, laya/train.py), but this one read
+ # plain utf-8, so the BOM became U+FEFF and a valid questions file was refused as "not valid JSON".
+ bom_questions = write_raw("bom-questions.json", b"\xef\xbb\xbf" + _json.dumps(INTENTS).encode("utf-8"))
+ code, out, err, stub = run_cli(["hello", "--questions", bom_questions], router=QuestionRecorder())
+ check("questions: a UTF-8 BOM file is read, not refused as invalid JSON",
+ code == 0 and stub.questions == INTENTS, "code %r err %r" % (code, err))
+
code, out, err, stub = run_cli(["hi", "--questions", INTENTS_PATH, "--preset", "triage"],
router=QuestionRecorder())
check("questions: two sources refuse each other",