feat: stream search, anti-crawl, aggregator, config, models
Implements the improvements from bot-search-mcp comparison (closes #5): - perf: asyncio.as_completed streaming + early termination (8s timeout) - feat: ResultAggregator (dedup + quality filter) - feat: anti-crawl enhancements for sogou_weixin.py - feat: config.py (pydantic-settings + .env support) - feat: models.py (data models with dataclasses) - docs: SKILL.md, README.md updates
This commit is contained in:
1 parent
06e3c6bdb9
commit
30158d8deb
5 files changed
+380
-57
No files matched your search
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
全局配置管理。
|
||||
|
||||
从 bot-search-mcp 移植,使用 pydantic-settings 管理环境变量。
|
||||
支持 .env 文件自动加载。
|
||||
|
||||
如果未安装 pydantic-settings,使用简单 os.environ 回退。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
try:
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""应用全局配置,支持环境变量 + .env 文件覆盖。"""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
# --- 搜索引擎配置 ---
|
||||
bing_api_key: str = ""
|
||||
bing_endpoint: str = ""
|
||||
baidu_api_key: str = ""
|
||||
baidu_qianfan_api_key: str = ""
|
||||
wolfram_app_id: str = ""
|
||||
twitter_bearer_token: str = ""
|
||||
|
||||
# --- 微信公众号搜索 ---
|
||||
wechat_search_enabled: bool = True
|
||||
wechat_request_delay: float = 1.0
|
||||
wechat_max_pages: int = 3
|
||||
|
||||
# --- 超时控制 ---
|
||||
engine_timeout: float = 15.0
|
||||
max_concurrent: int = 5
|
||||
|
||||
# --- 日志 ---
|
||||
log_level: str = "INFO"
|
||||
|
||||
except ImportError:
|
||||
|
||||
class Settings: # type: ignore
|
||||
"""回退配置类:无 pydantic-settings 时使用 os.environ。"""
|
||||
|
||||
def __init__(self):
|
||||
self.bing_api_key = os.environ.get("BING_API_KEY", "")
|
||||
self.bing_endpoint = os.environ.get("BING_ENDPOINT", "")
|
||||
self.baidu_api_key = os.environ.get("BAIDU_API_KEY", "")
|
||||
self.baidu_qianfan_api_key = os.environ.get(
|
||||
"BAIDU_QIANFAN_API_KEY", ""
|
||||
)
|
||||
self.wolfram_app_id = os.environ.get("WOLFRAM_APP_ID", "")
|
||||
self.twitter_bearer_token = os.environ.get(
|
||||
"TWITTER_BEARER_TOKEN", ""
|
||||
)
|
||||
self.wechat_search_enabled = (
|
||||
os.environ.get("WECHAT_SEARCH_ENABLED", "true").lower()
|
||||
== "true"
|
||||
)
|
||||
self.wechat_request_delay = float(
|
||||
os.environ.get("WECHAT_REQUEST_DELAY", "1.0")
|
||||
)
|
||||
self.wechat_max_pages = int(
|
||||
os.environ.get("WECHAT_MAX_PAGES", "3")
|
||||
)
|
||||
self.engine_timeout = float(
|
||||
os.environ.get("ENGINE_TIMEOUT", "15.0")
|
||||
)
|
||||
self.max_concurrent = int(
|
||||
os.environ.get("MAX_CONCURRENT", "5")
|
||||
)
|
||||
self.log_level = os.environ.get("LOG_LEVEL", "INFO")
|
||||
|
||||
|
||||
# 全局单例
|
||||
settings = Settings()
|
||||
Reference in new issue
Block a user