mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-04 08:28:36 +00:00
fix(providers): remove custom cloud httpx client, let SDK handle proxy defaults
chengyongru reviewed #4367 and identified that the cloud branch created a bare httpx.AsyncClient that lacked the SDK's default settings (follow_redirects, connection pool limits). Since the SDK's DefaultAsyncHttpxClient already has trust_env=True and proper defaults, the simplest fix is to let http_client stay None for cloud endpoints. Also updated the test to match the new behavior (http_client is None).
This commit is contained in:
parent
72b8fc806f
commit
0023f6d998
@ -417,14 +417,9 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
timeout=timeout_s,
|
timeout=timeout_s,
|
||||||
transport=httpx.AsyncHTTPTransport(proxy=None, limits=_local_limits),
|
transport=httpx.AsyncHTTPTransport(proxy=None, limits=_local_limits),
|
||||||
)
|
)
|
||||||
else:
|
# else: http_client stays None → SDK creates DefaultAsyncHttpxClient
|
||||||
# Cloud endpoints: respect proxy environment variables
|
# which already reads proxy env vars via trust_env=True, has proper
|
||||||
# (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) so corporate
|
# connection limits, and follows redirects.
|
||||||
# or VPN proxies work without explicit configuration.
|
|
||||||
http_client = httpx.AsyncClient(
|
|
||||||
timeout=timeout_s,
|
|
||||||
trust_env=True,
|
|
||||||
)
|
|
||||||
self._client = AsyncOpenAI(
|
self._client = AsyncOpenAI(
|
||||||
api_key=self._api_key_for_client,
|
api_key=self._api_key_for_client,
|
||||||
base_url=self._effective_base,
|
base_url=self._effective_base,
|
||||||
|
|||||||
@ -16,10 +16,10 @@ async def test_openai_compat_provider_defers_sdk_client_until_first_use() -> Non
|
|||||||
|
|
||||||
kwargs = mock_async_openai.call_args.kwargs
|
kwargs = mock_async_openai.call_args.kwargs
|
||||||
_assert_openai_compat_timeout(kwargs["timeout"])
|
_assert_openai_compat_timeout(kwargs["timeout"])
|
||||||
# Cloud endpoints get an httpx client with trust_env=True to respect
|
# Cloud endpoints pass http_client=None so the SDK creates its own
|
||||||
# proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY).
|
# DefaultAsyncHttpxClient, which already handles proxy env vars,
|
||||||
assert kwargs["http_client"] is not None
|
# connection limits, and redirects correctly.
|
||||||
assert kwargs["http_client"]._trust_env is True
|
assert kwargs["http_client"] is None
|
||||||
|
|
||||||
|
|
||||||
async def test_openai_compat_provider_sets_timeout_on_local_http_client() -> None:
|
async def test_openai_compat_provider_sets_timeout_on_local_http_client() -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user