-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix: migrate http clients to httpx2 #6826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| NOISY_LOGGERS = [ | ||
| "httpx", | ||
| "httpcore", | ||
| "httpx2", | ||
| "httpcore2", | ||
| "openai", | ||
| "watchfiles", | ||
| "anthropic", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
| from collections.abc import Mapping | ||
| from typing import TypeAlias | ||
|
|
||
| import httpx | ||
| import httpx2 | ||
|
|
||
| HTTPXTimeout: TypeAlias = httpx2.Timeout | httpx.Timeout | ||
| HTTPXLimits: TypeAlias = httpx2.Limits | httpx.Limits | ||
|
|
||
| LegacyTimeoutException = httpx.TimeoutException | ||
|
|
||
| _DEPRECATION_MESSAGE = ( | ||
| "httpx.Timeout inputs are deprecated and will no longer be supported in LiveKit Agents 2.0. " | ||
| "Use httpx2.Timeout instead." | ||
| ) | ||
|
|
||
|
|
||
| def warn_on_legacy_timeout(timeout: HTTPXTimeout | None) -> None: | ||
| if isinstance(timeout, httpx.Timeout): | ||
| warnings.warn(_DEPRECATION_MESSAGE, DeprecationWarning, stacklevel=3) | ||
|
|
||
|
|
||
| def to_httpx2_timeout(timeout: HTTPXTimeout | None) -> httpx2.Timeout | None: | ||
|
Comment on lines
+21
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 New public helper functions ship without the documentation the project requires The newly added HTTP-client compatibility helpers are published without any documentation ( Repository documentation rule and affected additionsCONTRIBUTING.md states: "If writing new methods/enums/classes, document them. This project uses pdoc3 for automatic API documentation generation, and every new addition has to be properly documented." AGENTS.md additionally requires Google-style docstrings. The new module Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| if timeout is None or isinstance(timeout, httpx2.Timeout): | ||
| return timeout | ||
|
|
||
| return httpx2.Timeout( | ||
| connect=timeout.connect, | ||
| read=timeout.read, | ||
| write=timeout.write, | ||
| pool=timeout.pool, | ||
| ) | ||
|
|
||
|
|
||
| def to_legacy_timeout(timeout: HTTPXTimeout) -> httpx.Timeout: | ||
| if isinstance(timeout, httpx.Timeout): | ||
| return timeout | ||
|
|
||
| return httpx.Timeout( | ||
| connect=timeout.connect, | ||
| read=timeout.read, | ||
| write=timeout.write, | ||
| pool=timeout.pool, | ||
| ) | ||
|
|
||
|
|
||
| def legacy_async_client( | ||
| *, | ||
| timeout: HTTPXTimeout, | ||
| limits: HTTPXLimits, | ||
| headers: Mapping[str, str] | None = None, | ||
| follow_redirects: bool = False, | ||
| ) -> httpx.AsyncClient: | ||
| if isinstance(limits, httpx2.Limits): | ||
| resolved_limits = httpx.Limits( | ||
| max_connections=limits.max_connections, | ||
| max_keepalive_connections=limits.max_keepalive_connections, | ||
| keepalive_expiry=limits.keepalive_expiry, | ||
| ) | ||
| else: | ||
| resolved_limits = limits | ||
|
|
||
| return httpx.AsyncClient( | ||
| timeout=to_legacy_timeout(timeout), | ||
| limits=resolved_limits, | ||
| headers=headers, | ||
| follow_redirects=follow_redirects, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.