-
Notifications
You must be signed in to change notification settings - Fork 428
[Bugfix][Router] Preserve full backend model metadata in /v1/models #927
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
Merged
ruizhang0101
merged 4 commits into
vllm-project:main
from
yzhan1:codex/debug-892-fork-updated
May 7, 2026
+139
−12
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import json | ||
| import logging | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm_router.routers.main_router import show_models | ||
| from vllm_router.service_discovery import EndpointInfo, ModelInfo | ||
|
|
||
|
|
||
| def _build_request(): | ||
| request = MagicMock() | ||
| request.app.state = MagicMock() | ||
| request.app.state.external_provider_registry = None | ||
| return request | ||
|
|
||
|
|
||
| def _build_endpoint(model_payload): | ||
| model_id = model_payload["id"] | ||
| return EndpointInfo( | ||
| url="http://engine", | ||
| model_names=[model_id], | ||
| Id="engine-1", | ||
| added_timestamp=0.0, | ||
| model_label=model_id, | ||
| sleep=False, | ||
| model_info={model_id: ModelInfo.from_dict(model_payload)}, | ||
| ) | ||
|
|
||
|
|
||
| def test_model_info_preserves_extra_fields(): | ||
| payload = { | ||
| "id": "test-model", | ||
| "object": "model", | ||
| "created": 123, | ||
| "owned_by": "vllm", | ||
| "root": "models/test-model", | ||
| "parent": None, | ||
| "max_model_len": 8192, | ||
| "permission": [{"id": "perm-1", "allow_sampling": True}], | ||
| } | ||
|
|
||
| model_info = ModelInfo.from_dict(payload) | ||
|
|
||
| assert model_info.extra_fields == { | ||
| "max_model_len": 8192, | ||
| "permission": [{"id": "perm-1", "allow_sampling": True}], | ||
| } | ||
| assert model_info.to_dict() == payload | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_show_models_returns_full_backend_model_payload(monkeypatch): | ||
| payload = { | ||
| "id": "rich-model", | ||
| "object": "model", | ||
| "created": 1774275193, | ||
| "owned_by": "vllm", | ||
| "root": "models/rich-model", | ||
| "parent": None, | ||
| "max_model_len": 262144, | ||
| "permission": [ | ||
| { | ||
| "id": "modelperm-1", | ||
| "object": "model_permission", | ||
| "allow_sampling": True, | ||
| "allow_logprobs": True, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| monkeypatch.setattr( | ||
| "vllm_router.routers.main_router.get_service_discovery", | ||
| lambda: MagicMock(get_endpoint_info=lambda: [_build_endpoint(payload)]), | ||
| ) | ||
|
|
||
| response = await show_models(_build_request()) | ||
|
|
||
| assert response.status_code == 200 | ||
| body = json.loads(response.body) | ||
| assert body["data"] == [payload] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_show_models_does_not_warn_for_preserved_backend_fields( | ||
| monkeypatch, caplog | ||
| ): | ||
| payload = { | ||
| "id": "rich-model", | ||
| "object": "model", | ||
| "created": 1774275193, | ||
| "owned_by": "vllm", | ||
| "root": "models/rich-model", | ||
| "parent": None, | ||
| "max_model_len": 262144, | ||
| "permission": [ | ||
| { | ||
| "id": "modelperm-1", | ||
| "object": "model_permission", | ||
| "allow_sampling": True, | ||
| "allow_logprobs": True, | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| monkeypatch.setattr( | ||
| "vllm_router.routers.main_router.get_service_discovery", | ||
| lambda: MagicMock(get_endpoint_info=lambda: [_build_endpoint(payload)]), | ||
| ) | ||
|
|
||
| with caplog.at_level(logging.WARNING, logger="vllm_router.protocols"): | ||
| response = await show_models(_build_request()) | ||
|
|
||
| assert response.status_code == 200 | ||
| assert "ignored" not in caplog.text |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.