[Frontend] supports interleaved thinking (#28531)
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
This commit is contained in:
@@ -240,6 +240,9 @@ class CustomChatCompletionMessageParam(TypedDict, total=False):
|
||||
tool_calls: Iterable[ChatCompletionMessageToolCallParam] | None
|
||||
"""The tool calls generated by the model, such as function calls."""
|
||||
|
||||
reasoning: str | None
|
||||
"""The reasoning content for interleaved thinking."""
|
||||
|
||||
|
||||
ChatCompletionMessageParam: TypeAlias = (
|
||||
OpenAIChatCompletionMessageParam
|
||||
@@ -265,6 +268,12 @@ class ConversationMessage(TypedDict, total=False):
|
||||
tool_calls: Iterable[ChatCompletionMessageToolCallParam] | None
|
||||
"""The tool calls generated by the model, such as function calls."""
|
||||
|
||||
reasoning: str | None
|
||||
"""The reasoning content for interleaved thinking."""
|
||||
|
||||
reasoning_content: str | None
|
||||
"""Deprecated: The reasoning content for interleaved thinking."""
|
||||
|
||||
|
||||
# Passed in by user
|
||||
ChatTemplateContentFormatOption = Literal["auto", "string", "openai"]
|
||||
@@ -1374,7 +1383,7 @@ def _parse_chat_message_content(
|
||||
) -> list[ConversationMessage]:
|
||||
role = message["role"]
|
||||
content = message.get("content")
|
||||
|
||||
reasoning = message.get("reasoning") or message.get("reasoning_content")
|
||||
if content is None:
|
||||
content = []
|
||||
elif isinstance(content, str):
|
||||
@@ -1396,6 +1405,12 @@ def _parse_chat_message_content(
|
||||
# follow the OpenAI spec.
|
||||
if "tool_calls" in parsed_msg and parsed_msg["tool_calls"] is not None:
|
||||
result_msg["tool_calls"] = list(parsed_msg["tool_calls"])
|
||||
# Include reasoning if present for interleaved thinking.
|
||||
if reasoning is not None:
|
||||
result_msg["reasoning"] = cast(str, reasoning)
|
||||
result_msg["reasoning_content"] = cast(
|
||||
str, reasoning
|
||||
) # keep compatibility
|
||||
elif role == "tool":
|
||||
parsed_msg = _ToolParser(message)
|
||||
if "tool_call_id" in parsed_msg:
|
||||
|
||||
Reference in New Issue
Block a user