角色业务范围收紧工单与模板;报价日期不当费用;未选舱不迁已报价;另开一票可清违禁 hold
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -103,6 +103,41 @@ _WRITE_KEYS = {
|
||||
# 建单前要看的当前字段。没写进这几项、但原话里出现过的,靠 sensitive_hold 记住。
|
||||
_SCAN_KEYS = ("品名", "货物品名", "起运港", "起运地", "始发站", "备注")
|
||||
|
||||
# 新开一票的说法。命中且本句没有违禁词时,丢掉上一句没改口的 hold。
|
||||
_FRESH_INQUIRY = re.compile(
|
||||
r"(查一下|帮我查|询一下|询个价|询价|请报价|报一下价|报个价|费用)"
|
||||
)
|
||||
# 只补量尺、件数、包装:不算新询价,旧 hold 继续有效。
|
||||
_MEASURE_SUPPLEMENT = re.compile(
|
||||
r"(?:"
|
||||
r"重量|毛重|体积|件数|货量|包装(?:方式|类型)?"
|
||||
r")\s*[::]?\s*\d"
|
||||
r"|\d+\s*(?:kgs?|kg|公斤|千克|吨|t|cbm|方|件|箱|托)",
|
||||
re.I,
|
||||
)
|
||||
|
||||
|
||||
def looks_like_fresh_inquiry(text: str) -> bool:
|
||||
"""
|
||||
当前句是不是另开一票,而不是接着补上一票的字段。
|
||||
|
||||
「查一下目的地吉隆坡的费用」算新开;「重量100KGS」不算。
|
||||
用来在本句已无违禁词时清掉 sticky hold,避免正常询价被上一句炸弹拖死。
|
||||
"""
|
||||
body = (text or "").strip()
|
||||
if not body:
|
||||
return False
|
||||
if _MEASURE_SUPPLEMENT.search(body) and not _FRESH_INQUIRY.search(body):
|
||||
return False
|
||||
return bool(_FRESH_INQUIRY.search(body))
|
||||
|
||||
|
||||
def scrub_blocked_scan_fields(facts: dict[str, Any]) -> None:
|
||||
"""新开一票时,把品名/起运/备注里仍带着违禁词的旧值清掉,避免 field_hit 再拦。"""
|
||||
for key in _SCAN_KEYS:
|
||||
if contains_blocked(str((facts or {}).get(key) or "")):
|
||||
facts[key] = ""
|
||||
|
||||
|
||||
def contains_blocked(text: str) -> bool:
|
||||
"""
|
||||
@@ -203,6 +238,7 @@ def judge(*, text: str, facts: dict[str, Any], hold: str) -> tuple[bool, str]:
|
||||
当前句已经把品名说成普通货(运送衣服、改成衣服、换成衣服):前面的违禁原话作废。
|
||||
同一句里先提到旧词再改口,按改口后的品名放行。
|
||||
只补重量、件数:旧原话继续有效。
|
||||
本句无违禁词且像另开一票(查一下…费用):旧 hold 作废,并清掉字段里残留的违禁词。
|
||||
品名改干净之后,起运地或备注里还留着违禁词,仍然拦截。
|
||||
会就地更新 facts 里本句写明的品名、起运地、备注。
|
||||
第三个返回值是本句写下的键,多段用来写回每一段,避免把别的字段盖掉。
|
||||
@@ -210,14 +246,23 @@ def judge(*, text: str, facts: dict[str, Any], hold: str) -> tuple[bool, str]:
|
||||
edits = apply_field_edits(text, facts)
|
||||
replaced = bool(spoken_cargo(text)) or is_cargo_rename(text)
|
||||
message_hit = contains_blocked(text)
|
||||
fresh = False
|
||||
if replaced and not contains_blocked(str(facts.get("品名") or "")):
|
||||
# 已经说出新的普通货品名。旧词留在这句里只是在改口,不再记住。
|
||||
new_hold = ""
|
||||
message_hit = False
|
||||
elif message_hit:
|
||||
new_hold = (text or "").strip() or (hold or "")
|
||||
elif hold and looks_like_fresh_inquiry(text):
|
||||
# 本句没有违禁词,且是另开一票(查一下…费用),上一句违禁原话作废。
|
||||
# 只补重量/件数不走这里,旧 hold 继续拦。
|
||||
fresh = True
|
||||
new_hold = ""
|
||||
scrub_blocked_scan_fields(facts)
|
||||
else:
|
||||
new_hold = hold or ""
|
||||
field_text = "\n".join(str((facts or {}).get(key) or "") for key in _SCAN_KEYS)
|
||||
blocked = message_hit or contains_blocked(new_hold) or contains_blocked(field_text)
|
||||
hold_hit = contains_blocked(new_hold)
|
||||
field_hit = contains_blocked(field_text)
|
||||
blocked = message_hit or hold_hit or field_hit
|
||||
return blocked, new_hold, edits
|
||||
|
||||
Reference in New Issue
Block a user