fix: 收紧跑题识别,避免股市等闲聊写入槽位

Co-authored-by: haijd <haijd@163.com>
This commit is contained in:
Cursor Agent
2026-09-20 05:52:45 +00:00
co-authored by haijd
parent 625a6a3a9d
commit 71cb593d63
+5 -5
View File
@@ -23,10 +23,10 @@ _DOMAIN_RE = re.compile(
# 明显跑题话题 # 明显跑题话题
_OFFTOPIC_RE = re.compile( _OFFTOPIC_RE = re.compile(
r"天气|气温|下雨|新闻|股票|基金|彩票|足球|篮球|电影|电视剧|游戏|" r"天气|气温|下雨|新闻|股票|股市|股指|大盘|基金|彩票|足球|篮球|电影|电视剧|游戏|"
r"笑话|段子|星座|运势|做饭|菜谱|旅游|机票|酒店|恋爱|八卦|" r"笑话|段子|星座|运势|做饭|菜谱|旅游|机票|酒店|恋爱|八卦|"
r"政治|选举|战争|加密货币|比特币|chatgpt|写诗|作文|数学题|" r"政治|选举|战争|加密货币|比特币|chatgpt|写诗|作文|数学题|"
r"编程作业|leetcode|今天吃什么", r"编程作业|leetcode|今天吃什么|炒股|买股",
re.I, re.I,
) )
@@ -74,10 +74,10 @@ def looks_off_topic(text: str) -> bool:
return False # greeting/ack 另判 return False # greeting/ack 另判
if looks_like_question(t): if looks_like_question(t):
return True return True
# 较长文本却无任何业务词 → 视为跑题 # 带疑问且无业务词 → 跑题
if len(t) >= 8 and not is_domain_related(t) and looks_like_question(t): if len(t) >= 4 and not is_domain_related(t) and looks_like_question(t):
return True return True
if len(t) >= 16 and not is_domain_related(t): if len(t) >= 10 and not is_domain_related(t):
return True return True
return False return False