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.

docs(email): the **extra paragraph must name the serializer behind absent-vs-null

Aashish96cd2e3dfcb6
diff --git a/laya/email.py b/laya/email.py
index b592faad..e7b76cae 100644
--- a/laya/email.py
+++ b/laya/email.py
@@ -281,10 +281,12 @@ def email_state(subject: str, body: str, sender: Optional[str] = None, clean: bo
Any other keyword becomes a field of the state, so it is read by the model; a typo here is an
input mutation, not an error. The exception is a keyword whose value is exactly ``None``: it is
- dropped rather than added, so ``email_state(..., thread_id=None)`` leaves no ``thread_id`` field
- at all -- an omitted field and a null one are the same state to the model. ``sender`` is dropped
- on the same call but by a different rule, falsiness rather than ``None``, so ``sender=""``
- leaves no ``from`` field either.
+ dropped rather than added, so ``email_state(..., thread_id=None)`` gives the same state as
+ leaving the keyword out. The key is absent, not null -- and the distinction reaches the model,
+ because `laya.common.serialize_state` turns the state into JSON before it is tokenized, so a
+ retained ``None`` would put ``"thread_id": null`` in the prompt. ``sender`` is dropped on the
+ same call by a different rule, falsiness rather than ``None``, so ``sender=""`` leaves no
+ ``from`` field either.
"""
state = {
"subject": (subject or "").strip(),
diff --git a/tests/test_email.py b/tests/test_email.py
index 4019ec44..54b56837 100644
--- a/tests/test_email.py
+++ b/tests/test_email.py
@@ -37,6 +37,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import laya # noqa: E402
from laya import email as email_module # noqa: E402
from laya import presets # noqa: E402
+from laya.common import serialize_state # noqa: E402
from laya.email import clean_email_body, email_state # noqa: E402
PASS, FAIL = [], []
@@ -828,6 +829,24 @@ check(
sorted(email_state("Billing", "Short body", sender=None, thread_id=None)),
["body", "subject"],
)
+# The rewritten paragraph claims the drop matters because the state reaches the model as JSON, so
+# that mechanism is checked against `serialize_state` rather than left as prose: a dropped key must
+# leave no `null` in the serialized prompt, and a retained one must.
+check_true(
+ "state/the mechanism the doc names really renders JSON",
+ "json.dumps" in inspect.getsource(serialize_state),
+ "`serialize_state` no longer serializes with JSON, so the paragraph's prompt claim is stale",
+)
+check(
+ "state/a dropped key leaves no null in the serialized state",
+ "null" in serialize_state(email_state("Billing", "Short body", sender=None, thread_id=None)),
+ False,
+)
+check(
+ "state/a keyword with a value does reach the serialized state",
+ '"thread_id": "t-9"' in serialize_state(email_state("Billing", "Short body", thread_id="t-9")),
+ True,
+)
print("\n%d passed, %d failed" % (len(PASS), len(FAIL)))