diff --git a/app/agent/tools/impl/search_web.py b/app/agent/tools/impl/search_web.py index 3a79ebf1..93dc2f28 100644 --- a/app/agent/tools/impl/search_web.py +++ b/app/agent/tools/impl/search_web.py @@ -1,5 +1,6 @@ import asyncio import json +import random import re from typing import Optional, Type, List, Dict @@ -72,10 +73,12 @@ class SearchWebTool(MoviePilotTool): """使用 Tavily API 进行搜索""" try: async with httpx.AsyncClient(timeout=SEARCH_TIMEOUT) as client: + # 从设置中随机选择一个 API Key(如果有多个) + tavity_api_key = random.choice(settings.TAVILY_API_KEY) response = await client.post( "https://api.tavily.com/search", json={ - "api_key": settings.TAVILY_API_KEY, + "api_key": tavity_api_key, "query": query, "search_depth": "basic", "max_results": max_results, diff --git a/app/core/config.py b/app/core/config.py index 88bc4609..6b2193f1 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -459,13 +459,14 @@ class ConfigModel(BaseModel): # AI推荐用户偏好 AI_RECOMMEND_USER_PREFERENCE: str = "" # Tavily API密钥(用于网络搜索) - TAVILY_API_KEY: str = "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" + TAVILY_API_KEY: List[str] = ["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", + "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", + "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"] # AI推荐条目数量限制 AI_RECOMMEND_MAX_ITEMS: int = 50 - class Settings(BaseSettings, ConfigModel, LogConfigModel): """ 系统配置类 @@ -869,7 +870,7 @@ class Settings(BaseSettings, ConfigModel, LogConfigModel): return rename_format.strip("/") def TMDB_IMAGE_URL( - self, file_path: Optional[str], file_size: str = "original" + self, file_path: Optional[str], file_size: str = "original" ) -> Optional[str]: """ 获取TMDB图片网址