httpx_compat
langroid/language_models/httpx_compat.py
Compatibility shim over the httpx / httpx2 split in the OpenAI SDK.
openai < 3 is built on httpx; openai >= 3 replaced it with
httpx2 (the Pydantic-maintained successor). Both expose the same
Client / AsyncClient / Timeout API, but each SDK major only
depends on its own family, so langroid must import the family that matches
the installed openai major rather than hard-coding httpx.
Everything in langroid that needs an HTTP-client type should go through this
module instead of importing httpx or httpx2 directly.
HTTPX_MODULE_NAME = 'httpx2' if _openai_major() >= 3 else 'httpx'
module-attribute
¶
Name of the httpx family the installed openai SDK is built on.
import_httpx()
¶
Import and return the httpx family matching the installed openai SDK.
The import is performed on every call (cheap: sys.modules caches it)
so callers can wrap it in try/except ImportError and report a
family-specific install hint.
Returns:
| Type | Description |
|---|---|
ModuleType
|
The |
ModuleType
|
(openai 3.x). |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the required package is not installed. |
Source code in langroid/language_models/httpx_compat.py
missing_httpx_message()
¶
Error text for http_client_config when the httpx family is missing.