[Refactor][Parser] Unify Response API to use parser.parse() like Chat Completion API (#45190)

Signed-off-by: sfeng33 <4florafeng@gmail.com>
This commit is contained in:
Flora Feng
2026-06-11 04:37:51 +00:00
committed by GitHub
parent f272dfdce1
commit 3a04061701
6 changed files with 101 additions and 211 deletions
+76 -3
View File
@@ -12,23 +12,96 @@ from openai.types.chat import (
from openai.types.chat.chat_completion_message_tool_call_param import (
Function as FunctionCallTool,
)
from openai.types.responses import ResponseFunctionToolCall, ResponseOutputItem
from openai.types.responses import (
ResponseFunctionToolCall,
ResponseOutputItem,
ResponseOutputMessage,
ResponseOutputText,
ResponseReasoningItem,
)
from openai.types.responses.response import ToolChoice
from openai.types.responses.response_function_tool_call_output_item import (
ResponseFunctionToolCallOutputItem,
)
from openai.types.responses.response_output_message import ResponseOutputMessage
from openai.types.responses.response_reasoning_item import ResponseReasoningItem
from openai.types.responses.response_output_text import Logprob
from openai.types.responses.response_reasoning_item import (
Content as ResponseReasoningTextContent,
)
from openai.types.responses.tool import Tool
from vllm import envs
from vllm.entrypoints.chat_utils import make_tool_call_id
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionMessageParam
from vllm.entrypoints.openai.engine.protocol import FunctionCall
from vllm.entrypoints.openai.responses.protocol import ResponseInputOutputItem
from vllm.logger import init_logger
from vllm.utils import random_uuid
logger = init_logger(__name__)
def build_response_output_items(
reasoning: str | None,
content: str | None,
tool_calls: list[FunctionCall] | None,
logprobs: list[Logprob] | None = None,
tool_call_id_type: str = "random",
) -> list[ResponseOutputItem]:
outputs: list[ResponseOutputItem] = []
if reasoning:
outputs.append(
ResponseReasoningItem(
id=f"rs_{random_uuid()}",
summary=[],
type="reasoning",
content=[
ResponseReasoningTextContent(text=reasoning, type="reasoning_text")
],
status=None,
)
)
if content:
outputs.append(
ResponseOutputMessage(
id=f"msg_{random_uuid()}",
content=[
ResponseOutputText(
text=content,
annotations=[],
type="output_text",
logprobs=logprobs,
)
],
role="assistant",
status="completed",
type="message",
)
)
if tool_calls:
for idx, tool_call in enumerate(tool_calls):
outputs.append(
ResponseFunctionToolCall(
id=f"fc_{random_uuid()}",
call_id=tool_call.id
if tool_call.id
else make_tool_call_id(
id_type=tool_call_id_type,
func_name=tool_call.name,
idx=idx,
),
type="function_call",
status="completed",
name=tool_call.name,
arguments=tool_call.arguments,
)
)
return outputs
def should_continue_final_message(
request_input: str | list[ResponseInputOutputItem],
) -> bool: