-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[gpt-oss] disable tool server initialization if no tool in request #25790
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
+148
−12
Merged
Changes from all commits
Commits
Show all changes
3 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,129 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| from contextlib import AsyncExitStack | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
| import pytest_asyncio | ||
|
|
||
| from vllm.entrypoints.context import ConversationContext | ||
| from vllm.entrypoints.openai.protocol import ResponsesRequest | ||
| from vllm.entrypoints.openai.serving_responses import OpenAIServingResponses | ||
| from vllm.entrypoints.tool_server import ToolServer | ||
|
|
||
|
|
||
| class MockConversationContext(ConversationContext): | ||
| """Mock conversation context for testing""" | ||
|
|
||
| def __init__(self): | ||
| self.init_tool_sessions_called = False | ||
| self.init_tool_sessions_args = None | ||
| self.init_tool_sessions_kwargs = None | ||
|
|
||
| def append_output(self, output) -> None: | ||
| pass | ||
|
|
||
| async def call_tool(self): | ||
| return [] | ||
|
|
||
| def need_builtin_tool_call(self) -> bool: | ||
| return False | ||
|
|
||
| def render_for_completion(self): | ||
| return [] | ||
|
|
||
| async def init_tool_sessions(self, tool_server, exit_stack, request_id, | ||
| mcp_tools): | ||
| self.init_tool_sessions_called = True | ||
| self.init_tool_sessions_args = (tool_server, exit_stack, request_id, | ||
| mcp_tools) | ||
|
|
||
| async def cleanup_session(self) -> None: | ||
| pass | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_serving_responses(): | ||
| """Create a mock OpenAIServingResponses instance""" | ||
| serving_responses = MagicMock(spec=OpenAIServingResponses) | ||
| serving_responses.tool_server = MagicMock(spec=ToolServer) | ||
| return serving_responses | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_context(): | ||
| """Create a mock conversation context""" | ||
| return MockConversationContext() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_exit_stack(): | ||
| """Create a mock async exit stack""" | ||
| return MagicMock(spec=AsyncExitStack) | ||
|
|
||
|
|
||
| class TestInitializeToolSessions: | ||
| """Test class for _initialize_tool_sessions method""" | ||
|
|
||
| @pytest_asyncio.fixture | ||
| async def serving_responses_instance(self): | ||
| """Create a real OpenAIServingResponses instance for testing""" | ||
| # Create minimal mocks for required dependencies | ||
| engine_client = MagicMock() | ||
| engine_client.get_model_config = AsyncMock() | ||
|
|
||
| model_config = MagicMock() | ||
| model_config.hf_config.model_type = "test" | ||
| model_config.get_diff_sampling_param.return_value = {} | ||
|
|
||
| models = MagicMock() | ||
|
|
||
| tool_server = MagicMock(spec=ToolServer) | ||
|
|
||
| # Create the actual instance | ||
| instance = OpenAIServingResponses( | ||
| engine_client=engine_client, | ||
| model_config=model_config, | ||
| models=models, | ||
| request_logger=None, | ||
| chat_template=None, | ||
| chat_template_content_format="auto", | ||
| tool_server=tool_server, | ||
| ) | ||
|
|
||
| return instance | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_initialize_tool_sessions(self, serving_responses_instance, | ||
| mock_context, mock_exit_stack): | ||
| """Test that method works correctly with only MCP tools""" | ||
|
|
||
| request = ResponsesRequest(input="test input", tools=[]) | ||
|
|
||
| # Call the method | ||
| await serving_responses_instance._initialize_tool_sessions( | ||
| request, mock_context, mock_exit_stack) | ||
| assert mock_context.init_tool_sessions_called is False | ||
|
|
||
| # Create only MCP tools | ||
| tools = [ | ||
| { | ||
| "type": "web_search_preview" | ||
| }, | ||
| { | ||
| "type": "code_interpreter", | ||
| "container": { | ||
| "type": "auto" | ||
| } | ||
| }, | ||
| ] | ||
|
|
||
| request = ResponsesRequest(input="test input", tools=tools) | ||
|
|
||
| # Call the method | ||
| await serving_responses_instance._initialize_tool_sessions( | ||
| request, mock_context, mock_exit_stack) | ||
|
|
||
| # Verify that init_tool_sessions was called | ||
| assert mock_context.init_tool_sessions_called |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe @Hanchenli also mentioned this issue. can we also cover this in unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me know if you have any thoughts @Hanchenli ?
I added a UT, should be ready for review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks good to me. The issue I mentioned was that the model might generate function_call requests even if we do not provide tools to them.