Files
inquiry_robot/inquiry-agent/agent/schema/sea_options.py
T
jillion886andCursor 19acbb9156 fix: 已出号后新一轮询价不带上一单字段
点名海运时丢掉旧陆运补问草稿,避免补字段误发填写样例图。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 18:27:13 +08:00

96 lines
3.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
海运运输分类:只认 Port to Port、其他。
本文件职责:从原话收成标准词、生成补问清单。
禁止:发明第三项;把分类带去 TMS;改六态。
线程:纯函数,可在 Worker 槽调用。
"""
from __future__ import annotations
SEA_CLASSES = ("Port to Port", "其他")
# 长词优先,避免 P2P 误伤其它词;门到门不在名单里。
_ALIASES = (
("port to port", "Port to Port"),
("港到港", "Port to Port"),
("p2p", "Port to Port"),
("其它", "其他"),
("其他", "其他"),
)
def canonicalize_sea_class(raw: str) -> str:
"""
把销售原话收成 Port to Port 或 其他;对不上返回空串。
「门到门」不算。先匹配更长别名。副作用:无。
"""
text = (raw or "").strip()
if not text:
return ""
lowered = text.lower()
for needle, canon in _ALIASES:
if needle in lowered or needle in text:
return canon
stripped = text.replace("运输分类", "").replace(":", "").replace(":", "").strip()
if stripped in SEA_CLASSES:
return stripped
return ""
def harvest_sea_class(text: str, current: dict[str, str] | None = None) -> dict[str, str]:
"""
当前句能认则覆盖;认不出则保留已有标准值。
参数:本轮原文、已有 facts。返回合并后的 facts 副本。
非法旧值会丢掉,避免「门到门」一直占着必填位。
"""
merged = dict(current or {})
found = canonicalize_sea_class(text or "")
if found:
merged["运输分类"] = found
return merged
kept = canonicalize_sea_class(str(merged.get("运输分类") or ""))
if kept:
merged["运输分类"] = kept
else:
merged.pop("运输分类", None)
return merged
# 运输分类用语,不能冒充贸易条款。销售原话写了「贸易条款」才保留。
_DOOR_TRADE_TERMS = frozenset(
{
"门到门",
"door to door",
"door-to-door",
"doortodoor",
"d2d",
}
)
def drop_invented_door_trade_terms(text: str, facts: dict[str, str] | None = None) -> dict[str, str]:
"""
丢掉冒充贸易条款的「门到门」。
测服 WO202609200013:原话没写贸易条款,确认卡却出现「贸易条款:门到门」。
门到门只是运输分类说法,不是 FOB/CIF 这类条款;原话没有「贸易条款」四字时不准收下。
销售明确写了「贸易条款:门到门」则保留原文,不改六态。
"""
merged = dict(facts or {})
trade = str(merged.get("贸易条款") or "").strip()
if not trade:
return merged
if "贸易条款" in (text or ""):
return merged
if trade.lower().replace(" ", "") in {x.replace(" ", "") for x in _DOOR_TRADE_TERMS} or trade in _DOOR_TRADE_TERMS:
merged.pop("贸易条款", None)
return merged
def sea_class_prompt() -> str:
"""缺运输分类时只列两项,不再追问「其他是什么」。"""
return "运输分类(必填):请回复 Port to Port 或 其他。"