mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-30 15:21:02 +00:00
fix: httpx v0.28.0 proxies bug (#2179)
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
This commit is contained in:
parent
abab4e3e65
commit
4da1809b31
@ -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):
|
||||
@ -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]):
|
||||
|
@ -16,7 +16,7 @@ from dbgpt.rag.knowledge.factory import KnowledgeFactory
|
||||
from dbgpt.util.i18n_utils import _
|
||||
|
||||
|
||||
class KnowledgeOperator(MapOperator[str, Knowledge]):
|
||||
class KnowledgeOperator(MapOperator[dict, Knowledge]):
|
||||
"""Knowledge Factory Operator."""
|
||||
|
||||
metadata = ViewMetadata(
|
||||
@ -91,10 +91,11 @@ class KnowledgeOperator(MapOperator[str, Knowledge]):
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user