From d86ad25f86d7f11ef875c959fd839627077935da Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Wed, 7 Feb 2024 23:58:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=AD=A3=E5=90=91=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/provider/requester/apis/chatcmpl.py | 4 ++++ pkg/utils/proxy.py | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/provider/requester/apis/chatcmpl.py b/pkg/provider/requester/apis/chatcmpl.py index 8630d4e3..c41b50d6 100644 --- a/pkg/provider/requester/apis/chatcmpl.py +++ b/pkg/provider/requester/apis/chatcmpl.py @@ -7,6 +7,7 @@ from typing import AsyncGenerator import openai import openai.types.chat.chat_completion as chat_completion +import httpx from pkg.provider.entities import Message @@ -24,6 +25,9 @@ class OpenAIChatCompletion(api.LLMAPIRequester): api_key="", base_url=self.ap.provider_cfg.data['openai-config']['base_url'], timeout=self.ap.provider_cfg.data['openai-config']['request-timeout'], + http_client=httpx.AsyncClient( + proxies=self.ap.proxy_mgr.get_forward_proxies() + ) ) async def _req( diff --git a/pkg/utils/proxy.py b/pkg/utils/proxy.py index 74228b86..7ebd3171 100644 --- a/pkg/utils/proxy.py +++ b/pkg/utils/proxy.py @@ -18,14 +18,14 @@ class ProxyManager: async def initialize(self): self.forward_proxies = { - "http": os.getenv("HTTP_PROXY") or os.getenv("http_proxy"), - "https": os.getenv("HTTPS_PROXY") or os.getenv("https_proxy"), + "http://": os.getenv("HTTP_PROXY") or os.getenv("http_proxy"), + "https://": os.getenv("HTTPS_PROXY") or os.getenv("https_proxy"), } if 'http' in self.ap.system_cfg.data['network-proxies']: - self.forward_proxies['http'] = self.ap.system_cfg.data['network-proxies']['http'] + self.forward_proxies['http://'] = self.ap.system_cfg.data['network-proxies']['http'] if 'https' in self.ap.system_cfg.data['network-proxies']: - self.forward_proxies['https'] = self.ap.system_cfg.data['network-proxies']['https'] + self.forward_proxies['https://'] = self.ap.system_cfg.data['network-proxies']['https'] def get_forward_proxies(self) -> dict: - return self.forward_proxies + return self.forward_proxies.copy()