修复三个问题:病句过滤、KB回复内容、截图保存日志
1. 病句过滤改进(monitor.py): - ≤5字短句:必须包含疑问词(什么/怎么/如何/为什么/吗/呢等)才放行 - 无疑问词的短句直接过滤(如'自行修?') - 5-50字病句:增加'过'字匹配(如'修正过后') 2. KB回复内容改进(auto_reply.py + knowledge_base.py): - _get_answer 改为返回 body(纯正文),不含 heading - KB搜索增加heading包含查询关键词的bonus - 文档头部(# 文档名)增加penalty,避免返回错误section 3. 截图保存日志改进(monitor.py): - QQ/微信截图保存失败日志从 debug 升级为 warning - 增加保存路径提示,便于定位问题
This commit is contained in:
+15
-7
@@ -1251,7 +1251,7 @@ class MessageMonitor:
|
||||
logger.debug(f"[qq] 调试截图: {_dbg_path}")
|
||||
_clean_old_ocr_debug(script_dir, keep=60)
|
||||
except Exception as e:
|
||||
logger.debug(f"[qq] 调试截图保存失败: {e}")
|
||||
logger.warning(f"[qq] 调试截图保存失败: {e} (路径: {os.path.join(script_dir, 'ocr_debug_qq_*.png')})")
|
||||
|
||||
# ⭐ 颜色像素检测:如果截图中只有 bot 蓝色气泡,无白色用户消息,跳过
|
||||
if not self._has_user_colors(im, "qq"):
|
||||
@@ -1354,7 +1354,7 @@ class MessageMonitor:
|
||||
# 清理 ocr_debug_* 调试图(unified pool)
|
||||
_clean_old_ocr_debug(script_dir, keep=60)
|
||||
except Exception as e:
|
||||
logger.debug(f"[wechat] 调试截图保存失败: {e}")
|
||||
logger.warning(f"[wechat] 调试截图保存失败: {e} (路径: {os.path.join(script_dir, 'ocr_debug_wx_*.png')})")
|
||||
|
||||
# ⭐ 颜色像素检测:如果截图中只有 bot 绿色气泡,无白色用户消息,跳过
|
||||
if not self._has_user_colors(im, "wechat"):
|
||||
@@ -1815,11 +1815,19 @@ class MessageMonitor:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 结构化面板 line={line!r}")
|
||||
continue
|
||||
|
||||
# —— OCR 病句检测:OCR 把消息"嚼碎"生成病句 ——
|
||||
# 特征:句子不完整、语义不通、缺少标点、片段化
|
||||
if len(line) > 5 and len(line) < 50:
|
||||
# 病句1:句子以动词结尾但缺少宾语(如"将其修正后重三")
|
||||
if re.search(r'[后以了]+.{0,3}$', line) and not re.search(r'[。!?,,;;::?]$', line):
|
||||
# —— OCR 短句/病句检测:OCR 把消息"嚼碎"生成碎片 ——
|
||||
# 通用疑问词(有这些词说明有查询意向,放行)
|
||||
_q_words = {"什么", "怎么", "如何", "为什么", "吗", "呢", "吧", "能", "可以", "有没有", "哪些", "哪", "哪几个"}
|
||||
# "自行修?" → 3字无查询意向碎片;"将其修正后重三" → 病句
|
||||
if len(line) <= 5:
|
||||
# ≤5字短句:必须包含疑问词才放行,否则是OCR碎片
|
||||
has_q = any(w in line for w in _q_words)
|
||||
if not has_q:
|
||||
logger.debug(f"[{platform}] OCR 过滤: 短句碎片(≤5字) line={line!r}")
|
||||
continue
|
||||
if 5 < len(line) < 50:
|
||||
# 病句1:句子以动词/助词结尾但缺少宾语且无标点
|
||||
if re.search(r'[后以了过]+.{0,3}$', line) and not re.search(r'[。!?,,;;::?]$', line):
|
||||
logger.debug(f"[{platform}] OCR 过滤: 病句(动词结尾) line={line!r}")
|
||||
continue
|
||||
# 病句2:句子以"三"结尾(OCR误读"试"为"三")
|
||||
|
||||
Reference in New Issue
Block a user