feat: switch text risk filtering to AI-first with keyword fallback

This commit is contained in:
2026-03-01 13:41:25 +08:00
parent 3c92611137
commit 1c266f2887
2 changed files with 126 additions and 5 deletions

View File

@@ -1687,16 +1687,21 @@ class CustomerServiceAgent:
# 前置风控:客户文本一旦命中政治/敏感询问,直接拒绝,避免“发图我看看”类答非所问
try:
from utils.content_filter import should_block_customer
map_hit = self._is_map_inquiry(message.msg)
political_hit = self._is_political_inquiry(message.msg)
if should_block_customer(message.msg) or political_hit or map_hit:
from utils.content_filter import should_block_customer_smart
risk_hit, risk_category, _risk_reason = await should_block_customer_smart(message.msg)
map_hit = self._is_map_inquiry(message.msg) or (risk_category == "map")
political_hit = self._is_political_inquiry(message.msg) or (risk_category == "political")
if risk_hit or political_hit or map_hit:
# 命中敏感询问时清空待报价队列,避免旧图残留污染后续会话
state.pending_image_urls.clear()
state.pending_requirements.clear()
self._sync_pending_quote_state(message.from_id, state)
reject_text = "地图这类不做哈,这边不接地图相关需求。"
if political_hit and not map_hit:
if risk_category == "sexual":
reject_text = "这类不做哈,涉黄擦边内容都不接。"
elif risk_category == "violent":
reject_text = "这类不做哈,暴力血腥相关都不接。"
elif political_hit and not map_hit:
reject_text = "这类不做哈,政治相关图片和人物都不接。"
reply = await self._rewrite_reply_with_ai(
message=message,
@@ -1711,6 +1716,7 @@ class CustomerServiceAgent:
customer_id=message.from_id,
map_hit=map_hit,
political_hit=political_hit,
risk_category=risk_category,
reply=reply,
)
return AgentResponse(reply=reply, should_reply=True, need_transfer=False)