refactor: extract text risk detectors from pydantic agent

This commit is contained in:
2026-03-01 15:49:45 +08:00
parent 62e5fed25c
commit 34b27d793e
2 changed files with 74 additions and 31 deletions

71
core/risk_text_helpers.py Normal file
View File

@@ -0,0 +1,71 @@
from __future__ import annotations
import re
def is_political_inquiry(text: str) -> bool:
"""文本前置风控:政治人物/政治事件/政治图片相关询问一律拒绝。"""
s = (text or "").strip().lower()
if not s:
return False
kw = (
"政治",
"涉政",
"党政",
"政治人物",
"政治事件",
"政治图片",
"政治海报",
"政治宣传",
"领导人",
"伟人",
"元帅",
"将军",
"红色人物",
"党史",
"天安门",
"人民大会堂",
"中南海",
"习近平",
"毛泽东",
"邓小平",
"江泽民",
"胡锦涛",
"李克强",
"周恩来",
"特朗普",
"拜登",
"普京",
"泽连斯基",
"trump",
"biden",
"putin",
"zelensky",
"xi jinping",
)
if any(k in s for k in kw):
return True
return bool(re.search(r"(元帅|将军|领导人|政治人物|政治事件).*(照片|图片|头像|原图)?", s))
def is_map_inquiry(text: str) -> bool:
"""地图类需求一律拒绝(按业务规则)。"""
s = (text or "").strip().lower()
if not s:
return False
kw = (
"地图",
"地形图",
"行政区划图",
"世界地图",
"中国地图",
"卫星地图",
"导航图",
"航海图",
"作战地图",
"军事地图",
"map",
"topographic map",
"satellite map",
)
return any(k in s for k in kw)