35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""客服/游客编排层:违禁词扫描后的分治(1B 拍板)。
|
||||
|
|
|
|||
|
|
底层 compliance_guard.sanitize_reply 仍返回 need_transfer=True;
|
|||
|
|
本模块在 customer/visitor 编排层决定是否真的转人工。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from app.utils.compliance_guard import COMPLIANCE_REJECT, sanitize_reply
|
|||
|
|
|
|||
|
|
DATA_QUERY_INTENTS = frozenset({
|
|||
|
|
"holding_query",
|
|||
|
|
"transaction_query",
|
|||
|
|
"risk_assessment_query",
|
|||
|
|
"suitability_check",
|
|||
|
|
"nav_query",
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
|
|||
|
|
def finalize_sanitized_reply(
|
|||
|
|
reply: str,
|
|||
|
|
*,
|
|||
|
|
intent: str | None = None,
|
|||
|
|
fact_text: str | None = None,
|
|||
|
|
data_query_intents: frozenset[str] | None = None,
|
|||
|
|
) -> tuple[str, bool]:
|
|||
|
|
"""数据查询 intent 命中违禁词 → 回退 fact_text;其余 → COMPLIANCE_REJECT;均不自动 transfer。"""
|
|||
|
|
allowed = data_query_intents or DATA_QUERY_INTENTS
|
|||
|
|
safe, hit = sanitize_reply(reply)
|
|||
|
|
if not hit:
|
|||
|
|
return safe, False
|
|||
|
|
if intent in allowed and fact_text:
|
|||
|
|
return fact_text, False
|
|||
|
|
return COMPLIANCE_REJECT, False
|