Skip to content

Commit e9b94f6

Browse files
maxnilzDouweM
andauthored
Fix auto-detection of HTTP proxy settings (#2917)
Signed-off-by: maxnilz <[email protected]> Co-authored-by: Douwe Maan <[email protected]>
1 parent 553ce06 commit e9b94f6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600,
783783
The client is cached based on the provider parameter. If provider is None, it's used for non-provider specific
784784
requests (like downloading images). Multiple agents and calls can share the same client when they use the same provider.
785785
786+
Each client will get its own transport with its own connection pool. The default pool size is defined by `httpx.DEFAULT_LIMITS`.
787+
786788
There are good reasons why in production you should use a `httpx.AsyncClient` as an async context manager as
787789
described in [encode/httpx#2026](https://github.com/encode/httpx/pull/2026), but when experimenting or showing
788790
examples, it's very useful not to.
@@ -793,6 +795,8 @@ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600,
793795
client = _cached_async_http_client(provider=provider, timeout=timeout, connect=connect)
794796
if client.is_closed:
795797
# This happens if the context manager is used, so we need to create a new client.
798+
# Since there is no API from `functools.cache` to clear the cache for a specific
799+
# key, clear the entire cache here as a workaround.
796800
_cached_async_http_client.cache_clear()
797801
client = _cached_async_http_client(provider=provider, timeout=timeout, connect=connect)
798802
return client
@@ -801,17 +805,11 @@ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600,
801805
@cache
802806
def _cached_async_http_client(provider: str | None, timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
803807
return httpx.AsyncClient(
804-
transport=_cached_async_http_transport(),
805808
timeout=httpx.Timeout(timeout=timeout, connect=connect),
806809
headers={'User-Agent': get_user_agent()},
807810
)
808811

809812

810-
@cache
811-
def _cached_async_http_transport() -> httpx.AsyncHTTPTransport:
812-
return httpx.AsyncHTTPTransport()
813-
814-
815813
DataT = TypeVar('DataT', str, bytes)
816814

817815

0 commit comments

Comments
 (0)