Skip to content

Commit

Permalink
fix: httpx v0.28.0 proxies bug (#2179)
Browse files Browse the repository at this point in the history
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
  • Loading branch information
Aries-ckt and fangyinc authored Dec 12, 2024
1 parent abab4e3 commit 4da1809
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 15 additions & 5 deletions dbgpt/model/utils/chatgpt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -142,19 +143,28 @@ def _build_openai_client(init_params: OpenAIParameters) -> Tuple[str, ClientType
if api_type == "azure":
from openai import AsyncAzureOpenAI

return api_type, AsyncAzureOpenAI(
async_client = AsyncAzureOpenAI(
api_key=openai_params["api_key"],
api_version=api_version,
azure_deployment=api_azure_deployment,
azure_endpoint=openai_params["base_url"],
http_client=httpx.AsyncClient(proxies=init_params.proxies),
)
else:
from openai import AsyncOpenAI

return api_type, AsyncOpenAI(
**openai_params, http_client=httpx.AsyncClient(proxies=init_params.proxies)
)
# Remove proxies for httpx AsyncClient when httpx version >= 0.28.0
httpx_version = metadata.version("httpx")
if httpx_version >= "0.28.0":
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 = AsyncOpenAI(**openai_params, http_client=http_client)
return api_type, async_client


class OpenAIStreamingOutputOperator(TransformStreamAbsOperator[ModelOutput, str]):
Expand Down
7 changes: 4 additions & 3 deletions dbgpt/rag/operators/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from dbgpt.util.i18n_utils import _


class KnowledgeOperator(MapOperator[str, Knowledge]):
class KnowledgeOperator(MapOperator[dict, Knowledge]):
"""Knowledge Factory Operator."""

metadata = ViewMetadata(
Expand Down Expand Up @@ -91,10 +91,11 @@ def __init__(

async def map(self, datasource: dict) -> Knowledge:
"""Create knowledge from datasource."""
source = datasource.get("source")
if self._datasource:
datasource = self._datasource
source = self._datasource
return await self.blocking_func_to_async(
KnowledgeFactory.create, datasource, self._knowledge_type
KnowledgeFactory.create, source, self._knowledge_type
)


Expand Down

0 comments on commit 4da1809

Please sign in to comment.