Standardize LLM clients and expose configurable base URLs.

This commit is contained in:
666ghj
2025-10-09 02:23:08 +08:00
parent 960608cee9
commit 49d4893780
22 changed files with 189 additions and 62 deletions
+6 -3
View File
@@ -12,7 +12,7 @@ from dataclasses import dataclass
# 添加项目根目录到Python路径以导入config
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
from config import GUIJI_QWEN3_API_KEY
from config import GUIJI_QWEN3_API_KEY, GUIJI_QWEN3_BASE_URL
# 添加utils目录到Python路径
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -38,21 +38,24 @@ class KeywordOptimizer:
使用硅基流动的Qwen3模型将Agent生成的搜索词优化为更贴近真实舆情的关键词
"""
def __init__(self, api_key: str = None):
def __init__(self, api_key: str = None, base_url: str = None):
"""
初始化关键词优化器
Args:
api_key: 硅基流动API密钥,如果不提供则从配置文件读取
base_url: 接口基础地址,默认使用配置文件提供的SiliconFlow地址
"""
self.api_key = api_key or GUIJI_QWEN3_API_KEY
if not self.api_key:
raise ValueError("未找到硅基流动API密钥,请在config.py中设置GUIJI_QWEN3_API_KEY")
self.base_url = base_url or GUIJI_QWEN3_BASE_URL
self.client = OpenAI(
api_key=self.api_key,
base_url="https://api.siliconflow.cn/v1"
base_url=self.base_url
)
self.model = "Qwen/Qwen3-30B-A3B-Instruct-2507"