From 1e274b43e27b3cf75da6650bf370f0d55d26bf24 Mon Sep 17 00:00:00 2001 From: jimi <1847930177@qq.com> Date: Sat, 28 Feb 2026 20:09:12 +0800 Subject: [PATCH] fix: hard-block political figures/events/images in risk and analyzer --- core/pydantic_ai_agent.py | 11 ++++++++--- image/image_analyzer.py | 9 +++++++-- utils/content_filter.py | 3 +++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/pydantic_ai_agent.py b/core/pydantic_ai_agent.py index 4fa2016..0d78a7e 100755 --- a/core/pydantic_ai_agent.py +++ b/core/pydantic_ai_agent.py @@ -569,7 +569,7 @@ class CustomerServiceAgent: @self.agent_risk.tool async def risk_filter(ctx: RunContext[AgentDeps], text: str = "") -> str: - return "这类不接哦,抱歉哈。" + return "这类不做哈,政治/敏感内容都不接。" @self.agent.tool async def remove_background(ctx: RunContext[AgentDeps], image_url: str) -> str: @@ -1053,7 +1053,7 @@ class CustomerServiceAgent: def _get_risk_prompt(self) -> str: return """你是淘宝客服的风控助手,负责敏感/违规内容的前置拦截与替代话术。 规则: -- 黄色/擦边/涉政等不接单,礼貌拒绝 +- 黄色/擦边/涉政/政治人物/政治事件/政治图片等不接单,礼貌拒绝 - 输出不超过1句话""" def _get_customer_profile_context(self, customer_id: str) -> str: @@ -1454,7 +1454,12 @@ class CustomerServiceAgent: processing_kw = ["安排", "处理一下", "开始做", "做一下", "尽快", "加急", "付款了", "已付款"] similar_kw = ["有一样的", "有一样吗", "一样的吗", "类似的", "类似的吗", "同款", "相似", "类似吗"] order_markers = ["[系统订单信息]", "订单状态", "买家已付款"] - risk_kw = ["黄色", "擦边", "色情", "涉黄", "涉政", "政治", "裸", "不雅"] + risk_kw = [ + "黄色", "擦边", "色情", "涉黄", "涉政", "政治", "裸", "不雅", + "天安门", "政治人物", "政治事件", "领导人", "党政", + "习近平", "毛泽东", "邓小平", "江泽民", "胡锦涛", + "特朗普", "拜登", "普京", "泽连斯基", + ] target_agent = self.agent_after_sale if state.stage == "售后" else self.agent if any(k in msg_lower for k in risk_kw): target_agent = self.agent_risk diff --git a/image/image_analyzer.py b/image/image_analyzer.py index 5ded00f..9a4296f 100755 --- a/image/image_analyzer.py +++ b/image/image_analyzer.py @@ -252,6 +252,11 @@ class ImageAnalyzer: FORBIDDEN_CONTENT_KEYWORDS = ( # 党政/涉政 "党政", "涉政", "政治人物", "领导人", "国旗", "国徽", "党徽", "党旗", "时政宣传", + "政治事件", "时政", "政要", "政治海报", "政治宣传", "政治标语", + "天安门", "人民大会堂", "中南海", + "习近平", "毛泽东", "邓小平", "江泽民", "胡锦涛", "李克强", "周恩来", + "中国共产党", "共产党", "中共", "党代会", "两会", "人大", "政协", + "trump", "donald trump", "biden", "putin", "zelensky", "xi jinping", # 黄暴血腥 "黄色", "擦边", "裸露", "色情", "性暗示", "暴力", "凶杀", "打斗", "枪击", "血腥", "尸体", "虐待", # 英文兜底 @@ -668,8 +673,8 @@ class ImageAnalyzer: if forbidden_scene or sensitive_hit: feasibility = "no" risk = "high" - note = "含党政/涉黄/暴力/血腥等敏感内容,不接单" - reason = (reason or "敏感内容") + " | 敏感内容不接单" + note = "含政治/党政/涉黄/暴力/血腥等敏感内容,不接单" + reason = (reason or "敏感内容") + " | 敏感内容不接单(政治类一律拒单)" price_suggest = 0 # 确保是 5 的倍数 diff --git a/utils/content_filter.py b/utils/content_filter.py index 32575dd..d39f79e 100755 --- a/utils/content_filter.py +++ b/utils/content_filter.py @@ -14,6 +14,9 @@ _SENSITIVE_PATTERNS = { "党政": [ r"习近平", r"共产党", r"党中央", r"政治局", r"六四", r"天安门", r"法轮功", r"台独", r"藏独", r"疆独", r"邪教", + r"政治人物", r"政治事件", r"领导人", r"党政", r"时政", + r"特朗普", r"拜登", r"普京", r"泽连斯基", + r"trump", r"biden", r"putin", r"zelensky", r"xi\s*jinping", ], "暴力": [ r"杀人", r"砍人", r"捅人", r"枪击", r"爆炸", r"恐怖袭击",