feat(faq): 缓存高频问题及答案,命中直接返回预置答案,不走dify

This commit is contained in:
sophie committed 2026-06-17 16:46:17 +08:00
1 parent 3264ed1e07
commit cf7cc11ffc
32 files changed
+3504 -180

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
"""
backend/app/services/faq_hot_settings.py
用途:读取热点 FAQ 离线聚合环境变量(权威默认值在仓库根 `.env.shared`)。
依赖:os.environ(由 config._load_environment_files 在启动时加载)。
逻辑:hot_faq_aggregator、hot_faq_candidate_store 通过本模块读配置,不经过 config.py。
"""
import os
from typing import Any
def read_faq_hot_env(key: str, default: Any) -> Any:
"""
读取单个 FAQ_HOT_* 环境变量并按 default 类型转换。
@param key - 环境变量名,如 FAQ_HOT_WINDOW_DAYS
@param default - 未配置时的兜底值,同时决定返回类型
@returns 转换后的配置值
"""
raw = os.getenv(key)
if raw is None or str(raw).strip() == '':
return default
text = str(raw).strip()
if isinstance(default, bool):
return text.lower() == 'true'
if isinstance(default, float):
return float(text)
if isinstance(default, int):
return int(text)
return text