Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/entrypoints/openai/test_response_api_with_harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,22 @@ async def test_function_calling_required(client: OpenAI, model_name: str):
)


@pytest.mark.asyncio
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_system_message_with_tools(client: OpenAI, model_name: str):
from vllm.entrypoints.harmony_utils import get_system_message

# Test with custom tools enabled - commentary channel should be available
sys_msg = get_system_message(with_custom_tools=True)
valid_channels = sys_msg.content[0].channel_config.valid_channels
assert "commentary" in valid_channels

# Test with custom tools disabled - commentary channel should be removed
sys_msg = get_system_message(with_custom_tools=False)
valid_channels = sys_msg.content[0].channel_config.valid_channels
assert "commentary" not in valid_channels


@pytest.mark.asyncio
@pytest.mark.parametrize("model_name", [MODEL_NAME])
async def test_function_calling_full_history(client: OpenAI, model_name: str):
Expand Down
4 changes: 3 additions & 1 deletion vllm/entrypoints/openai/serving_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,9 @@ def _make_request_with_harmony(
sys_msg = get_system_message(
reasoning_effort=request.reasoning_effort,
browser_description=None,
python_description=None)
python_description=None,
with_custom_tools=request.tools is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, it would be great to add a unit test for this, there are some examples here the test likely doesn't even need the model to run, just that the messages are being generated properly here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small nit would be that this will activate the commentary channel even if an empty list of tools is passed in, which is not uncommon. We could avoid that by using some like bool(request.tools) instead of request.tools is not None. But, I separately discovered this issue, Alec pointed me to this PR, and agree that this fix is needed to get accurate tool calling in Chat Completions with gpt-oss models.

Without this PR, I regularly see the models outputting non-built-in tool calls to the analysis channel, which isn't where they should go.

)
messages.append(sys_msg)

# Add developer message.
Expand Down