From bfb23e600ae26246bcdb65245fb911f35f1b7668 Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Wed, 13 Aug 2025 11:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=90=86=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=85=81=E8=AE=B8=E9=80=9A?= =?UTF-8?q?=E8=BF=87HTTP=E5=92=8CHTTPS=E4=BB=A3=E7=90=86=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E8=AF=B7=E6=B1=82=EF=BC=8C=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE=E6=8F=8F=E8=BF=B0=E5=92=8CSchema?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E4=BB=A3=E7=90=86=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../built_in/WEB_SEARCH_TOOL/plugin.py | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plugins/built_in/WEB_SEARCH_TOOL/plugin.py b/src/plugins/built_in/WEB_SEARCH_TOOL/plugin.py index 8b2532dba..4d50f691a 100644 --- a/src/plugins/built_in/WEB_SEARCH_TOOL/plugin.py +++ b/src/plugins/built_in/WEB_SEARCH_TOOL/plugin.py @@ -185,7 +185,27 @@ class URLParserTool(BaseTool): 使用本地库(httpx, BeautifulSoup)解析URL,并调用LLM进行总结。 """ try: - async with httpx.AsyncClient(timeout=15.0, follow_redirects=True) as client: + # 读取代理配置 + enable_proxy = self.get_config("proxy.enable_proxy", False) + proxies = None + + if enable_proxy: + http_proxy = self.get_config("proxy.http_proxy", None) + https_proxy = self.get_config("proxy.https_proxy", None) + + if http_proxy or https_proxy: + proxies = {} + if http_proxy: + proxies["http://"] = http_proxy + if https_proxy: + proxies["https://"] = https_proxy + logger.info(f"使用代理配置: {proxies}") + + client_kwargs = {"timeout": 15.0, "follow_redirects": True} + if proxies: + client_kwargs["proxies"] = proxies + + async with httpx.AsyncClient(**client_kwargs) as client: response = await client.get(url) response.raise_for_status() @@ -377,7 +397,7 @@ class WEBSEARCHPLUGIN(BasePlugin): config_file_name: str = "config.toml" # 配置文件名 # 配置节描述 - config_section_descriptions = {"plugin": "插件基本信息", "exa": "EXA相关配置", "components": "组件设置"} + config_section_descriptions = {"plugin": "插件基本信息", "exa": "EXA相关配置", "proxy": "链接本地解析代理配置", "components": "组件设置"} # 配置Schema定义 config_schema: dict = { @@ -389,6 +409,11 @@ class WEBSEARCHPLUGIN(BasePlugin): "exa":{ "api_key":ConfigField(type=str, default="None", description="exa的API密钥") }, + "proxy": { + "http_proxy": ConfigField(type=str, default=None, description="HTTP代理地址,格式如: http://proxy.example.com:8080"), + "https_proxy": ConfigField(type=str, default=None, description="HTTPS代理地址,格式如: http://proxy.example.com:8080"), + "enable_proxy": ConfigField(type=bool, default=False, description="是否启用代理") + }, "components":{ "enable_web_search_tool":ConfigField(type=bool, default=True, description="是否启用联网搜索tool"), "enable_url_tool":ConfigField(type=bool, default=True, description="是否启用URL解析tool")