修复网页对话并接入 SearXNG 搜索
This commit is contained in:
+25
-1
@@ -67,6 +67,11 @@ def _env_float(key: str, default: float) -> float:
|
||||
return default
|
||||
|
||||
|
||||
def _env_bool(key: str, default: bool) -> bool:
|
||||
value = _env(key, "true" if default else "false").strip().lower()
|
||||
return value in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- LLM
|
||||
|
||||
@dataclass
|
||||
@@ -133,6 +138,24 @@ class ContextConfig:
|
||||
memory_timeout_s: float = 0.3 # 检索超时,方案要求"记忆失败不阻塞对话"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 联网搜索
|
||||
|
||||
@dataclass
|
||||
class SearchConfig:
|
||||
"""SearXNG 搜索后端。
|
||||
|
||||
默认关闭,避免开发机没有 SearXNG 时改变普通对话行为;部署机显式设置
|
||||
SEARCH_ENABLED=true。服务只需暴露在助手所在机器的回环地址。
|
||||
"""
|
||||
|
||||
enabled: bool = field(default_factory=lambda: _env_bool("SEARCH_ENABLED", False))
|
||||
base_url: str = field(
|
||||
default_factory=lambda: _env("SEARXNG_BASE_URL", "http://127.0.0.1:18080"))
|
||||
timeout_s: float = field(default_factory=lambda: _env_float("SEARCH_TIMEOUT_S", 6.0))
|
||||
max_results: int = field(default_factory=lambda: _env_int("SEARCH_MAX_RESULTS", 5))
|
||||
language: str = field(default_factory=lambda: _env("SEARCH_LANGUAGE", "zh-CN"))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- 语音
|
||||
|
||||
def _default_model_dir() -> Path:
|
||||
@@ -199,6 +222,7 @@ class AppConfig:
|
||||
llm: LLMConfig = field(default_factory=local_llm_config)
|
||||
llm_fallback: LLMConfig = field(default_factory=deepseek_config)
|
||||
context: ContextConfig = field(default_factory=ContextConfig)
|
||||
search: SearchConfig = field(default_factory=SearchConfig)
|
||||
voice: VoiceConfig = field(default_factory=VoiceConfig)
|
||||
memory: MemoryConfig = field(default_factory=MemoryConfig)
|
||||
|
||||
@@ -212,6 +236,6 @@ class AppConfig:
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AppConfig", "LLMConfig", "ContextConfig", "VoiceConfig", "MemoryConfig",
|
||||
"AppConfig", "LLMConfig", "ContextConfig", "SearchConfig", "VoiceConfig", "MemoryConfig",
|
||||
"load_env", "local_llm_config", "deepseek_config", "PROJECT_ROOT", "ENV_FILE",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user