refactor(serve): split chat_completions endpoint into a package - #4840
Open
lvhan028 wants to merge 1 commit into
Open
refactor(serve): split chat_completions endpoint into a package#4840lvhan028 wants to merge 1 commit into
lvhan028 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the OpenAI /v1/chat/completions endpoint implementation from a single large module into a dedicated chat_completions package, aligning its layout with the existing responses/ package and adding migration tests to enforce backward-compatible import paths.
Changes:
- Introduces
lmdeploy.serve.openai.endpoints.chat_completionsas a package with split-outprotocol,validation,logprobs,logits_processors, andservingmodules. - Moves chat-specific Pydantic models into
endpoints/chat_completions/protocol.pywhile keeping shared models inlmdeploy.serve.openai.protocol. - Adds migration equivalence tests to assert package structure and re-export/class-identity invariants.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_chat_completions_package_migration.py | Adds structural migration tests for package layout + model re-export identity. |
| lmdeploy/serve/openai/protocol.py | Removes chat-specific models and re-exports them for backward compatibility. |
| lmdeploy/serve/openai/endpoints/chat_completions/validation.py | Extracts request validation logic for chat completions. |
| lmdeploy/serve/openai/endpoints/chat_completions/serving.py | Updates chat completions serving module to use the new split modules. |
| lmdeploy/serve/openai/endpoints/chat_completions/protocol.py | New canonical home for chat-specific Pydantic models. |
| lmdeploy/serve/openai/endpoints/chat_completions/logprobs.py | Extracts logprobs construction helpers. |
| lmdeploy/serve/openai/endpoints/chat_completions/logits_processors.py | Extracts logit-bias logits processor. |
| lmdeploy/serve/openai/endpoints/chat_completions/init.py | Adds lazy register export to avoid circular imports. |
| lmdeploy/serve/openai/endpoints/init.py | Adds lazy create_openai_router export to avoid circular imports. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+400
to
+420
| # Re-export chat completion models for backward compatibility. | ||
| # Canonical home is now endpoints/chat_completions/protocol.py. This trailing | ||
| # import is deliberately placed at the end of the module so that all shared | ||
| # models above are fully defined before chat_completions.protocol imports them. | ||
| from lmdeploy.serve.openai.endpoints.chat_completions.protocol import ( # noqa: E402,F401 | ||
| ChatCompletionRequest, | ||
| ChatCompletionResponse, | ||
| ChatCompletionResponseChoice, | ||
| ChatCompletionResponseStreamChoice, | ||
| ChatCompletionStreamResponse, | ||
| ChatCompletionTokenLogprob, | ||
| ChatMessage, | ||
| ChoiceLogprobs, | ||
| DeltaFunctionCall, | ||
| DeltaMessage, | ||
| DeltaToolCall, | ||
| ExtractedToolCallInformation, | ||
| FunctionCall, | ||
| ToolCall, | ||
| TopLogprob, | ||
| ) |
Aligns with the responses/ package layout. Splits the 633-line chat_completions.py into protocol/validation/logprobs/logits_processors/ serving modules. Chat-specific models move to endpoints/chat_completions/protocol.py; shared models stay in the top-level protocol.py with backward-compat re-exports. No behavior change. Co-Authored-By: Claude <noreply@anthropic.com>
lvhan028
force-pushed
the
refactor/chat-completions-package
branch
from
August 10, 2026 01:37
39a7a3e to
3fb7c3a
Compare
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.
Aligns with the responses/ package layout. Splits the 633-line chat_completions.py into protocol/validation/logprobs/logits_processors/ serving modules. Chat-specific models move to
endpoints/chat_completions/protocol.py; shared models stay in the top-level protocol.py with backward-compat re-exports. No behavior change.
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
Please describe the motivation of this PR and the goal you want to achieve through this PR.
Modification
Please briefly describe what modification is made in this PR.
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist