[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
@@ -413,13 +413,14 @@ class ChatCompletionRequest(OpenAIBaseModel):
@model_validator(mode="before")
@classmethod
def _materialize_tool_calls_before(cls, data: Any) -> Any:
"""Eagerly convert tool_calls generators/iterators to lists.
def _normalize_messages_before(cls, data: Any) -> Any:
"""Pre-process message dicts before Pydantic field validation.
Must run before Pydantic field validation so that one-shot
generators are not consumed during union type matching of
ChatCompletionAssistantMessageParam (which types tool_calls
as Iterable[...]).
Performs two normalizations in a single pass:
- Converts tool_calls generators/iterators to lists so one-shot
generators are not consumed during union type matching.
- Renames the deprecated ``reasoning_content`` field to
``reasoning`` so downstream code only needs to check one field.
"""
if not isinstance(data, dict):
return data
@@ -432,6 +433,9 @@ class ChatCompletionRequest(OpenAIBaseModel):
tool_calls = msg.get("tool_calls")
if tool_calls is not None and not isinstance(tool_calls, list):
msg["tool_calls"] = list(tool_calls)
reasoning_content = msg.pop("reasoning_content", None)
if reasoning_content is not None and msg.get("reasoning") is None:
msg["reasoning"] = reasoning_content
return data
@model_validator(mode="after")