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(email): `From:` starting a sentence deleted the request
PerryLink6ffd49638a4c
diff --git a/laya/email.py b/laya/email.pyindex d8bf4f4c..a4a6dcf2 100644--- a/laya/email.py+++ b/laya/email.py@@ -21,7 +21,12 @@ _QUOTE_HEADERS = [re.compile(r"^\s*-{2,}\s*(Original|Forwarded) Message\s*-{2,}", re.I),re.compile(r"^\s*-{2,}\s*(Mensagem (original|encaminhada)|Mensaje (original|reenviado))\s*-{2,}", re.I),re.compile(r"^\s*_{8,}\s*$"),- re.compile(r"^\s*From:\s.+$", re.I),+ # `From:` opens ordinary prose too ("From: my side the integration works, but please+ # refund..."), and a reply header always carries the sender, so the header is only+ # recognised when an address follows -- the same rule as `De:` below. A bare+ # `From: Name` header is caught by _HEADER_FROM_NAME/_HEADER_NEXT instead, which need the+ # header's own `Sent:`/`Date:` line to tell it apart from a sentence.+ re.compile(r"^\s*From:\s.*[@<]", re.I),# `De:` also opens ordinary Portuguese/Spanish lines ("De: 10/09 a 15/09"), so the Outlook# header is only recognised when it carries an addressre.compile(r"^\s*De:\s.*[@<]", re.I),@@ -33,8 +38,13 @@ _ATTRIBUTION_HEAD = re.compile(r"^\s*(On|Em|El) (?=.*\d)", re.I)# Exchange often leaves the address out of Outlook's reply header ("De: Maria Souza"), so a bare `De:`# only cuts when the header's own `Enviado:` line, or a dated `Data:`/`Fecha:` line, follows it.# `Para:` is not enough: "De: 10/09 / Para: 15/09" is how a leave request reads.-_HEADER_FROM_NAME = re.compile(r"^\s*De:\s+\S", re.I)-_HEADER_NEXT = re.compile(r"^\s*(Enviad[oa]( em| el)?:\s|(Data|Fecha):\s.*\d{4})", re.I)+#+# The same is true of a bare English `From: Maria Souza`, which is why the marker above needs+# this rule: the English client lines are the translations of the two `De:` neighbours. A line+# that only looks like prose still has to be told apart from a header by its neighbours, so the+# English pair is "From: <name>" followed by "Sent:"/"Date:".+_HEADER_FROM_NAME = re.compile(r"^\s*(De|From):\s+\S", re.I)+_HEADER_NEXT = re.compile(r"^\s*(Enviad[oa]( em| el)?:\s|Sent:\s|(Data|Fecha|Date):\s.*\d{4})", re.I)_SIGNATURE_MARKERS = [re.compile(r"^\s*--\s*$"),# A closing line is the closing word plus punctuation and at most a name. Anything else ondiff --git a/tests/test_email.py b/tests/test_email.pyindex eab9c612..0d13424a 100644--- a/tests/test_email.py+++ b/tests/test_email.py@@ -264,6 +264,65 @@ check("Preciso das férias.\nDe: 10/09 a 15/09\nPode aprovar?",)+# ------------------------------------------- `From:` starts prose, not only a quote header (#338)+# The marker used to be `^\s*From:\s.+$`, which matched any line beginning "From: ". English+# prose opens that way ("From: my side the integration works, but please refund ..."), so the+# request was deleted and the model answered an empty body. A reply header always carries the+# sender, so the marker is gated on an address -- the rule `De:` above already uses, for the+# same reason. The suite had no `From:` case at all before this, which is why it stayed green.+for label, body in [+ ("the reported case",+ "Hi team,\nFrom: my side the integration works, but please refund the duplicate charge today.\nThanks"),+ ("lowercase", "Hi,\nfrom: my side the integration works, but please refund the charge.\nThanks"),+ ("uppercase", "Hi,\nFROM: my side the integration works, but please refund the charge.\nThanks"),+ ("extra spacing", "Hi,\nFrom: my side the integration works, but please refund the charge.\nThanks"),+ ("mid-body", "Hello,\nFrom: what I can see the charge was taken twice, please refund it.\nRegards"),+]:+ check_true("en/`From:` prose keeps the request: " + label,+ "refund" in clean_email_body(body), clean_email_body(body))++# The positive controls: a real quoted header block still goes, and takes its quoted request+# with it, so the fix does not simply stop cutting on `From:`.+for label, body in [+ ("address then Sent:",+ "Hi,\nPlease look at this.\n\nFrom: Alice <[email protected]>\nSent: Monday\n"+ "To: Bob\nSubject: Refund\n\nPlease refund the duplicate charge to my card."),+ ("address only", "Hi,\nSee below.\n\nFrom: [email protected]\nPlease refund the duplicate charge."),+ ("angle address", "Hi,\nSee below.\n\nFrom: <[email protected]>\nPlease refund the duplicate charge."),+ ("name and address",+ "Hi,\nSee below.\n\nFrom: Alice Smith <[email protected]>\nPlease refund the duplicate charge."),+]:+ check("en/quoted block still cut: " + label, clean_email_body(body), "Hi,\nPlease look at this."+ if label == "address then Sent:" else "Hi,\nSee below.")++# ...and the request in the new part is kept even when a quoted block follows it.+check(+ "en/`From:` quote header keeps the new request",+ clean_email_body("Hi,\nPlease refund the duplicate charge today.\n\n"+ "From: Alice <[email protected]>\nSent: Monday\n\nOld thread: refund the first charge."),+ "Hi,\nPlease refund the duplicate charge today.",+)++# A bare `From: Name` header, with no address, is the English counterpart of `De: Maria Souza`:+# the marker above cannot cut it (that is the prose case), so it is recognised by its neighbours+# instead. Before this, only the Portuguese/Spanish `Enviado:`/`Data:` pair was a neighbour, so an+# English quote header without an address leaked its whole quoted block into the body.+for label, body in [+ ("then Sent:", "Hi,\nSee below.\n\nFrom: Alice Smith\nSent: Monday, 21 Sep 2026\n\nPlease refund."),+ ("then Date:", "Hi,\nSee below.\n\nFrom: Alice Smith\nDate: 21/09/2026\n\nPlease refund."),+ ("one-word name, then Sent:", "Hi,\nSee below.\n\nFrom: Alice\nSent: Monday\n\nPlease refund."),+]:+ check("en/bare `From:` header still cut: " + label, clean_email_body(body), "Hi,\nSee below.")++# A bare `From:` with no header neighbour is not distinguishable from prose, and a dropped+# request is the worse error, so it is kept.+for label, body in [+ ("From: Name then To:", "Hi,\nSee below.\n\nFrom: Alice Smith\nTo: Bob\n\nPlease refund the charge."),+ ("From: Name alone", "Hi,\nSee below.\n\nFrom: Alice Smith\nPlease refund the charge."),+]:+ check_true("en/bare `From:` with no header neighbour is kept: " + label,+ "refund" in clean_email_body(body), clean_email_body(body))+# --------------------------------------------------------------- Brazilian clients and footersBOLETO = "Preciso da segunda via do boleto."for label, footer in [