fix(core): Support of 'reasoning' type in 'convert_to_openai_messages' (#33050)

This commit is contained in:
Mohammad Mohtashim
2025-09-29 18:17:05 +05:00
committed by GitHub
parent c456c8ae51
commit 33a6def762
2 changed files with 62 additions and 1 deletions

View File

@@ -1385,7 +1385,7 @@ def convert_to_openai_messages(
},
}
)
elif block.get("type") == "thinking":
elif block.get("type") in ["thinking", "reasoning"]:
content.append(block)
else:
err = (

View File

@@ -1484,3 +1484,64 @@ def test_get_buffer_string_with_empty_content() -> None:
expected = "Human: \nAI: \nSystem: "
actual = get_buffer_string(messages)
assert actual == expected
def test_convert_to_openai_messages_reasoning_content() -> None:
"""Test convert_to_openai_messages with reasoning content blocks."""
# Test reasoning block with empty summary
msg = AIMessage(content=[{"type": "reasoning", "summary": []}])
result = convert_to_openai_messages(msg, text_format="block")
expected = {"role": "assistant", "content": [{"type": "reasoning", "summary": []}]}
assert result == expected
# Test reasoning block with summary content
msg_with_summary = AIMessage(
content=[
{
"type": "reasoning",
"summary": [
{"type": "text", "text": "First thought"},
{"type": "text", "text": "Second thought"},
],
}
]
)
result_with_summary = convert_to_openai_messages(
msg_with_summary, text_format="block"
)
expected_with_summary = {
"role": "assistant",
"content": [
{
"type": "reasoning",
"summary": [
{"type": "text", "text": "First thought"},
{"type": "text", "text": "Second thought"},
],
}
],
}
assert result_with_summary == expected_with_summary
# Test mixed content with reasoning and text
mixed_msg = AIMessage(
content=[
{"type": "text", "text": "Regular response"},
{
"type": "reasoning",
"summary": [{"type": "text", "text": "My reasoning process"}],
},
]
)
mixed_result = convert_to_openai_messages(mixed_msg, text_format="block")
expected_mixed = {
"role": "assistant",
"content": [
{"type": "text", "text": "Regular response"},
{
"type": "reasoning",
"summary": [{"type": "text", "text": "My reasoning process"}],
},
],
}
assert mixed_result == expected_mixed