[HTTPXodus] migrate httpx to httpx2 with dual import - #3931
Open
ProgrammerPlus1998 wants to merge 1 commit into
Open
[HTTPXodus] migrate httpx to httpx2 with dual import#3931ProgrammerPlus1998 wants to merge 1 commit into
ProgrammerPlus1998 wants to merge 1 commit into
Conversation
Use the actively maintained httpx2 fork (Pydantic Services) when running on Python 3.10+, falling back to httpx on 3.8/3.9. Single call site only: fastchat/serve/openai_api_server.py's generate_completion_stream. Refs: lm-sys#3929
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3929
What this PR does
Switches FastChat's single httpx call site to
httpx2via a dual import. On Python ≥ 3.10 the runtime binds tohttpx2; on 3.8 / 3.9 (which FastChat still supports and whichhttpx2cannot run on) it falls back tohttpx.requires-pythonis not changed — this PR does not drop any currently-supported interpreter.Diff summary
2 files, +6 / −2 (commit
4ea6a03):pyproject.toml— added"httpx2>=2.12.0; python_version >= \"3.10\""next to the existing"httpx". Thepython_versionmarker means httpx2 is only installed on runtimes that can run it; httpx stays in deps for 3.8/3.9.fastchat/serve/openai_api_server.py— top-of-fileimport httpxreplaced with thetry: import httpx2 as httpx; except ModuleNotFoundError: import httpxblock. This is the only call site in the entire package; non-streaming paths useaiohttp, and controller / model-worker / gradio / monitor / judge code never imports httpx.Test results
Validated in a fresh venv (Python 3.12.12):
pip install -e .— resolves to bothhttpx-0.28.1andhttpx2-2.12.0(the marker correctly selects httpx2 on 3.12).srv = importlib.import_module("fastchat.serve.openai_api_server"); srv.httpx.__version__ == "2.12.0"— thetrybranch wins.srv.httpx.__version__ == "0.28.1". Theexceptbranch works as expected. This simulates a 3.8/3.9 install where httpx2 is not present.python -W error -c "import fastchat.serve.openai_api_server"— no import-time warnings.black==23.3.0 --check fastchat/serve/openai_api_server.py— clean (the project pinsblack==23.3.0in itsdevextras;format.shuses the same version).The repo's
tests/test_image_utils.pyfails to collect on stockmain(pre-existing — it importsresize_image_and_return_image_in_bytesandimage_moderation_filterfromfastchat.utils, which are not defined there). Verified by stash + re-test on a clean checkout. Unrelated to this PR. The remainingtests/test_*.pyfiles are all integration tests requiring a live model worker + controller + api server, which can't run in a unit-test context. None referencehttpxdirectly.Notes for reviewer
httpx2verifies TLS against the OS trust store instead of the bundledcertifi. FastChat deployments that front worker endpoints with TLS (e.g. reverse-proxied multi-node setups) and rely on a custom certifi CA bundle may needSSL_CERT_FILE/SSL_CERT_DIRafter the switch. Worth a line in the deployment docs.v0.2.36in 2024-02, last commit onmainis aconstants.pybump in 2025-06-02; the hosted Chatbot Arena moved to LMArena in 2024-09). The migration itself is tiny and safe; whether to take it is a judgement call about how much ongoing investment this stack is getting. We're flagging it becausehttpxis unpinned inpyproject.toml, so a breakinghttpx1.0 stable would land in installs without warning.requires-pythonis unchanged at>=3.8. If maintainers later decide to drop 3.8/3.9, the dual-import can be replaced with a hardimport httpx2in a follow-up PR.Happy to revise per review — and equally happy to close this PR if the maintainers would rather wait for
httpx1.0 stable. 🙏