修复2问题: KB误匹配+返回全文 / Ctrl+C无法停止

1. KB匹配与返回全文
   - _poll中过滤纯时间/日期格式文本(OCR时间戳分割残留)->不入KB搜索
   - knowledge_base.py子串fallback要求query>=4字符,避免"19:15"等短时间戳误匹配
   - auto_reply._get_answer: 非Q&A文档只返回content前500字符,不返回整篇文件
   - 时间戳文本不进入KB + 短query不子串匹配 + 非Q&A截取 = 三层兜底

2. Ctrl+C无法停止
   - ThreadPoolExecutor创建非daemon线程->进程无法退出->必须杀CMD
     改用daemon thread + Event.wait(timeout): daemon线程不阻塞进程退出
   - main.py注册signal.signal(SIGINT) handler: 收到Ctrl+C后stop监控+quit窗口
   - 移除from concurrent.futures导入,替换为import signal
This commit is contained in:
youpaishidifu
2026-07-26 15:30:55 +08:00
parent 6d0974ea8f
commit 7bdc7ad637
16 changed files with 58 additions and 21 deletions
+9 -5
View File
@@ -67,15 +67,19 @@ class AutoReply:
def _get_answer(self, platform: str, msg: str, doc: dict, score: float) -> str or None:
"""提取答案 + 防重复检查。
优先返回 doc['answer'](Q&A 段),兜底用整段 content。
非 Q&A 文档限制返回内容首 500 字符,避免子串匹配触发后返回整篇文件。
"""
answer = (doc.get("answer") or doc["content"]).strip()
answer = doc.get("answer")
if answer:
answer = answer.strip()
else:
# 非 Q&A 文档 → 取 content 前半段(最多 500 字符),不返回全文
content = doc.get("content", "").strip()
answer = content[:497] + "..." if len(content) > 500 else content
if not answer:
return None
# 截取过长内容
if len(answer) > 500:
answer = answer[:497] + "..."
# 防重复指纹
fp = hash(f"{platform}:{msg}:{answer[:80]}")
replied_set = self._replied.setdefault(platform, set())