[Bugfix] Fix KeyError in parse_response_input for reasoning items with optional content (#34499)

Signed-off-by: jeonsworld <jeonsworld@gmail.com>
This commit is contained in:
Eunkwang Jeon
2026-03-13 00:13:36 +08:00
committed by GitHub
parent f444c05c32
commit bdc2343454
3 changed files with 101 additions and 6 deletions
+13 -5
View File
@@ -138,8 +138,12 @@ def _parse_chat_format_message(chat_msg: dict) -> list[Message]:
def response_input_to_harmony(
response_msg: ResponseInputOutputItem,
prev_responses: list[ResponseOutputItem | ResponseReasoningItem],
) -> Message:
"""Convert a single ResponseInputOutputItem into a Harmony Message."""
) -> Message | None:
"""Convert a single ResponseInputOutputItem into a Harmony Message.
Returns None for reasoning items with empty or absent content so
the caller can skip them.
"""
if not isinstance(response_msg, dict):
response_msg = response_msg.model_dump()
if "type" not in response_msg or response_msg["type"] == "message":
@@ -172,9 +176,13 @@ def response_input_to_harmony(
response_msg["output"],
)
elif response_msg["type"] == "reasoning":
content = response_msg["content"]
assert len(content) == 1
msg = Message.from_role_and_content(Role.ASSISTANT, content[0]["text"])
content = response_msg.get("content")
if content and len(content) >= 1:
reasoning_text = "\n".join(item["text"] for item in content)
msg = Message.from_role_and_content(Role.ASSISTANT, reasoning_text)
msg = msg.with_channel("analysis")
else:
return None
elif response_msg["type"] == "function_call":
msg = Message.from_role_and_content(Role.ASSISTANT, response_msg["arguments"])
msg = msg.with_channel("commentary")
+1 -1
View File
@@ -1086,7 +1086,7 @@ class OpenAIServingResponses(OpenAIServing):
prev_outputs = []
for response_msg in request.input:
new_msg = response_input_to_harmony(response_msg, prev_outputs)
if new_msg.author.role != "system":
if new_msg is not None and new_msg.author.role != "system":
messages.append(new_msg)
# User passes in a tool call request and its output. We need