Skip to content
Open
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
63 changes: 63 additions & 0 deletions tests/entrypoints/openai/responses/test_harmony_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from vllm.entrypoints.openai.responses.harmony import (
harmony_to_response_output,
response_input_to_harmony,
response_previous_input_to_harmony,
)

Expand Down Expand Up @@ -93,6 +94,68 @@ def test_tool_message_with_empty_content(self):
assert messages[0].content[0].text == ""


class TestResponseInputToHarmony:
"""Tests for the Responses API response_input_to_harmony function."""

@staticmethod
def _tool_call() -> ResponseFunctionToolCall:
return ResponseFunctionToolCall(
type="function_call",
call_id="call_1",
name="get_weather",
arguments='{"city": "Paris"}',
)

def test_function_call_output_with_string_output(self):
"""Test parsing a function call output with string output."""
response_msg = {
"type": "function_call_output",
"call_id": "call_1",
"output": "The weather in Paris is sunny, 18°C",
}

msg = response_input_to_harmony(response_msg, [self._tool_call()])

assert msg.author.role == Role.TOOL
assert msg.author.name == "functions.get_weather"
assert msg.content[0].text == "The weather in Paris is sunny, 18°C"

def test_function_call_output_with_list_output(self):
"""Test parsing a function call output with a content part list.

The Responses API accepts `output` as either a string or a list of
content parts, so the parts must be flattened into a single string
before the Harmony message is built.
"""
response_msg = {
"type": "function_call_output",
"call_id": "call_1",
"output": [
{"type": "input_text", "text": "The weather in Paris "},
{"type": "input_text", "text": "is sunny, 18°C"},
],
}

msg = response_input_to_harmony(response_msg, [self._tool_call()])

assert msg.author.role == Role.TOOL
assert msg.author.name == "functions.get_weather"
assert msg.content[0].text == "The weather in Paris is sunny, 18°C"

def test_function_call_output_with_empty_list_output(self):
"""Test parsing a function call output with an empty content list."""
response_msg = {
"type": "function_call_output",
"call_id": "call_1",
"output": [],
}

msg = response_input_to_harmony(response_msg, [self._tool_call()])

assert msg.author.role == Role.TOOL
assert msg.content[0].text == ""


class TestHarmonyToResponseOutput:
"""Tests for harmony_to_response_output function."""

Expand Down
2 changes: 1 addition & 1 deletion vllm/entrypoints/openai/responses/harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def response_input_to_harmony(
raise ValueError(f"No call message found for {call_id}")
msg = Message.from_author_and_content(
Author.new(Role.TOOL, f"functions.{call_response.name}"),
response_msg["output"],
flatten_input_text_content(response_msg["output"]) or "",
)
msg = msg.with_channel("commentary")
msg = msg.with_recipient("assistant")
Expand Down
Loading