From 68ad48ff552bbc407d56a800d475643b88f843d2 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 3 Feb 2025 14:11:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DHTTP=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=90=8E=E4=B8=8D=E7=94=9F=E6=95=88=20#319?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/core_lifecycle.py | 5 ++--- astrbot/core/provider/sources/openai_source.py | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/astrbot/core/core_lifecycle.py b/astrbot/core/core_lifecycle.py index dd49c6957..8f9e9b3d7 100644 --- a/astrbot/core/core_lifecycle.py +++ b/astrbot/core/core_lifecycle.py @@ -25,9 +25,8 @@ class AstrBotCoreLifecycle: self.astrbot_config = astrbot_config self.db = db - if self.astrbot_config['http_proxy']: - os.environ['https_proxy'] = self.astrbot_config['http_proxy'] - os.environ['http_proxy'] = self.astrbot_config['http_proxy'] + os.environ['https_proxy'] = self.astrbot_config['http_proxy'] + os.environ['http_proxy'] = self.astrbot_config['http_proxy'] async def initialize(self): logger.info("AstrBot v"+ VERSION) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index edea41946..5f25abeb7 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -1,6 +1,6 @@ import base64 import json -import re +import os from openai import AsyncOpenAI, NOT_GIVEN from openai.types.chat.chat_completion import ChatCompletion @@ -195,6 +195,11 @@ class ProviderOpenAIOfficial(Provider): if 'tool' in str(e).lower() and 'support' in str(e).lower(): logger.error(f"疑似该模型不支持函数调用工具调用。请输入 /tool off_all") + if 'Connection error.' in str(e): + proxy = os.environ.get("http_proxy", None) + if proxy: + logger.error(f"可能为代理原因,请检查代理是否正常。当前代理: {proxy}") + raise e if kwargs.get("persist", True) and llm_response: