From 1db755941fad1947b41063a3baf5aee808d558db Mon Sep 17 00:00:00 2001 From: aries_ckt <916701291@qq.com> Date: Wed, 11 Dec 2024 18:56:38 +0800 Subject: [PATCH] fix:add proxy parameter when httpx >= 0.28.0 --- dbgpt/model/utils/chatgpt_utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dbgpt/model/utils/chatgpt_utils.py b/dbgpt/model/utils/chatgpt_utils.py index 0d669b6d7..d6efca6ce 100644 --- a/dbgpt/model/utils/chatgpt_utils.py +++ b/dbgpt/model/utils/chatgpt_utils.py @@ -48,6 +48,7 @@ class OpenAIParameters: api_azure_deployment: Optional[str] = None full_url: Optional[str] = None proxies: Optional["ProxiesTypes"] = None + proxy: Optional["ProxyTypes"] = None def _initialize_openai_v1(init_params: OpenAIParameters): @@ -155,9 +156,14 @@ def _build_openai_client(init_params: OpenAIParameters) -> Tuple[str, ClientType # Remove proxies for httpx AsyncClient when httpx version >= 0.28.0 httpx_version = metadata.version("httpx") if httpx_version >= "0.28.0": - http_client = httpx.AsyncClient() - else: + if init_params.proxy: + http_client = httpx.AsyncClient(proxy=init_params.proxy) + else: + http_client = httpx.AsyncClient() + elif init_params.proxies: http_client = httpx.AsyncClient(proxies=init_params.proxies) + else: + http_client = httpx.AsyncClient() async_client.http_client = http_client return api_type, async_client