[Frontend] Normalize reasoning_content to reasoning for client compatibility (#42664)

Signed-off-by: Ben Browning <bbrownin@redhat.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Ben Browning
2026-05-20 21:23:47 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 7e5070934e
commit 346cf163a1
2 changed files with 65 additions and 6 deletions
@@ -61,3 +61,58 @@ def test_chat_completion_request_with_tool_choice_but_no_tools(tool_choice):
"tools": None,
}
)
def test_reasoning_content_normalized_to_reasoning():
request = ChatCompletionRequest.model_validate(
{
"messages": [
{"role": "user", "content": "What is 2+2?"},
{
"role": "assistant",
"content": "4",
"reasoning_content": "2+2 equals 4",
},
{"role": "user", "content": "Are you sure?"},
],
"model": "facebook/opt-125m",
}
)
assistant_msg = request.messages[1]
assert assistant_msg.get("reasoning") == "2+2 equals 4"
assert "reasoning_content" not in assistant_msg
def test_reasoning_takes_precedence_over_reasoning_content():
request = ChatCompletionRequest.model_validate(
{
"messages": [
{"role": "user", "content": "What is 2+2?"},
{
"role": "assistant",
"content": "4",
"reasoning": "from reasoning field",
"reasoning_content": "from reasoning_content field",
},
],
"model": "facebook/opt-125m",
}
)
assistant_msg = request.messages[1]
assert assistant_msg.get("reasoning") == "from reasoning field"
assert "reasoning_content" not in assistant_msg
def test_no_reasoning_fields_unchanged():
request = ChatCompletionRequest.model_validate(
{
"messages": [
{"role": "user", "content": "Hello"},
{"role": "assistant", "content": "Hi"},
],
"model": "facebook/opt-125m",
}
)
assistant_msg = request.messages[1]
assert assistant_msg.get("reasoning") is None
assert "reasoning_content" not in assistant_msg