Files
inquiry_robot/inquiry-agent/agent/schema/fingerprint.py
T

41 lines
1.3 KiB
Python

"""
相同询价内容指纹。
本文件职责:用已确认查价字段生成可比较的键,供主账全库检索相同需求(展示用,不复用工单号)。
禁止:用自然语言模糊相似;禁止写六态。
"""
from __future__ import annotations
import hashlib
from typing import Any
def ascii_idempotency_key(raw: str) -> str:
"""
企微/主账 HTTP 头必须是 ASCII。中文指纹原样塞进 X-Idempotency-Key 会直接崩,销售收不到回复。
"""
text = (raw or "").strip()
if not text:
return ""
try:
text.encode("ascii")
return text
except UnicodeEncodeError:
return "sha256:" + hashlib.sha256(text.encode("utf-8")).hexdigest()
def inquiry_fingerprint(facts: dict[str, Any], *, business_line: str) -> str:
"""
生成相同内容键。
组成:业务线 + 起运 + 目的 + 品名 + 件数/货量 + 毛重 + 体积 + 报价日期。
空运箱型不在空运必填里;海运箱型箱量若有则纳入。
"""
line = (business_line or "").strip().upper()
keys = ["起运港", "目的港", "品名", "件数", "货量", "毛重", "体积", "箱型箱量", "整柜或拼柜", "报价日期"]
parts = [line]
for key in keys:
parts.append(str(facts.get(key) or "").strip())
return "|".join(parts)