refactor: 重构配置管理和截图功能,切换LLM提供商至智谱AI

重构配置管理器以支持打包环境路径处理
将LLM分析器从OpenAI迁移至智谱AI API
替换Playwright截图功能为Selenium实现
更新默认配置中的API端点和模型
This commit is contained in:
2026-01-27 11:11:24 +08:00
parent e8210b4d88
commit f256bd0852
5 changed files with 147 additions and 124 deletions

View File

@@ -13,9 +13,9 @@ class ConfigManager:
DEFAULT_CONFIG = {
"llm_api": {
"base_url": "https://integrate.api.nvidia.com/v1",
"api_key": "",
"model": "deepseek-ai/deepseek-r1",
"base_url": "https://open.bigmodel.cn/api/paas/v4",
"model": "glm-4.7-flash",
"timeout": 120,
"retry_times": 3
},
@@ -46,9 +46,17 @@ class ConfigManager:
}
def __init__(self, config_path: str = "config.json"):
self.config_path = Path(config_path)
import sys
# 确定配置文件的正确路径
if getattr(sys, 'frozen', False):
# 打包后的环境
current_dir = Path(sys.executable).parent
self.config_path = current_dir / config_path
else:
# 开发环境
self.config_path = Path(config_path)
self.config = self._load_config()
logger.info(f"配置管理器初始化完成,配置文件: {config_path}")
logger.info(f"配置管理器初始化完成,配置文件: {self.config_path}")
def _load_config(self) -> Dict[str, Any]:
"""加载配置文件"""
@@ -59,13 +67,14 @@ class ConfigManager:
loaded_config = json.load(f)
# 合并默认配置,确保所有键都存在
merged = self._merge_config(self.DEFAULT_CONFIG, loaded_config)
logger.info("配置加载成功")
logger.info(f"配置加载成功目标URL: {merged.get('spider', {}).get('target_url', '未设置')}")
return merged
except (json.JSONDecodeError, IOError) as e:
logger.error(f"配置文件加载失败,使用默认配置: {e}")
return self.DEFAULT_CONFIG.copy()
else:
logger.warning(f"配置文件不存在: {self.config_path},使用默认配置")
logger.warning(f"默认配置目标URL: {self.DEFAULT_CONFIG.get('spider', {}).get('target_url', '未设置')}")
return self.DEFAULT_CONFIG.copy()
def _merge_config(self, default: Dict, loaded: Dict) -> Dict:
@@ -114,13 +123,13 @@ class ConfigManager:
current[keys[-1]] = value
return self.save_config()
def update_llm_api(self, base_url: str = None, api_key: str = None,
def update_llm_api(self, api_key: str = None, base_url: str = None,
model: str = None, timeout: int = None, retry_times: int = None):
"""更新LLM API配置"""
if base_url:
self.config["llm_api"]["base_url"] = base_url
if api_key:
self.config["llm_api"]["api_key"] = api_key
if base_url:
self.config["llm_api"]["base_url"] = base_url
if model:
self.config["llm_api"]["model"] = model
if timeout: