feat(faq): 缓存高频问题及答案,命中直接返回预置答案,不走dify
This commit is contained in:
1 parent
3264ed1e07
commit
cf7cc11ffc
32 files changed
+3504
-180
No files matched your search
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
backend/app/services/faq_text_utils.py
|
||||
|
||||
用途:FAQ / 热点问句归一化等纯文本工具,供 faq_cache 与 hot_faq_aggregator 共用。
|
||||
依赖:无外部业务模块。
|
||||
逻辑:保证离线聚合与在线命中使用同一 normalize 规则。
|
||||
"""
|
||||
import re
|
||||
|
||||
|
||||
def normalize_faq_query(text: str) -> str:
|
||||
"""
|
||||
归一化问句文本,便于精确匹配与 ChatLog 分组。
|
||||
核心逻辑:trim → 小写 → 去除空白与常见中英文标点。
|
||||
@param text - 原始问句
|
||||
@returns 归一化后的字符串;空输入返回空串
|
||||
"""
|
||||
value = str(text or "").strip().lower()
|
||||
value = re.sub(r"[\s\u3000,。!?、;:""''()()\[\]【】\-—·,.!?;:'\"]+", "", value)
|
||||
return value
|
||||
Reference in new issue
Block a user