11"""Network error handling utilities for providers."""
22
33import ssl
4+ import types
45
56import httpx
67
@@ -89,6 +90,7 @@ def create_proxy_client(
8990 proxy : str | None = None ,
9091 headers : dict [str , str ] | None = None ,
9192 verify : ssl .SSLContext | str | bool | None = None ,
93+ httpx_module : types .ModuleType | None = None ,
9294) -> httpx .AsyncClient :
9395 """Create an httpx AsyncClient with proxy configuration if provided.
9496
@@ -105,12 +107,19 @@ def create_proxy_client(
105107 headers: Optional custom headers to include in every request
106108 verify: Optional override for TLS verification. Defaults to the shared
107109 system SSL context when not provided.
110+ httpx_module: Optional httpx module to use for creating the client.
111+ In packaged environments (PyInstaller, Nuitka, etc.), the packaging
112+ tool may collect httpx as two separate copies. When the caller needs
113+ the created client to pass isinstance checks inside another library
114+ (e.g., openai), pass that library's own ``httpx`` module here so
115+ the client is created from the same class object.
108116
109117 Returns:
110118 An httpx.AsyncClient created with the shared system SSL context; the proxy is applied only if one is provided.
111119 """
120+ _httpx = httpx_module or httpx
112121 resolved_verify = _SYSTEM_SSL_CTX if verify is None else verify
113122 if proxy :
114123 logger .info (f"[{ provider_label } ] 使用代理: { proxy } " )
115- return httpx .AsyncClient (proxy = proxy , verify = resolved_verify , headers = headers )
116- return httpx .AsyncClient (verify = resolved_verify , headers = headers )
124+ return _httpx .AsyncClient (proxy = proxy , verify = resolved_verify , headers = headers )
125+ return _httpx .AsyncClient (verify = resolved_verify , headers = headers )
0 commit comments