Unverified Commit b07555d2 authored by Andrew Xia's avatar Andrew Xia Committed by GitHub
Browse files

[responsesAPI][2] parse ResponseFunctionToolCallOutputItem (#29383)


Signed-off-by: default avatarAndrew Xia <axia@fb.com>
Co-authored-by: default avatarAndrew Xia <axia@fb.com>
parent 0353d2e1
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import pytest import pytest
from openai.types.responses.response_function_tool_call_output_item import (
ResponseFunctionToolCallOutputItem,
)
from openai.types.responses.response_reasoning_item import ( from openai.types.responses.response_reasoning_item import (
Content, Content,
ResponseReasoningItem, ResponseReasoningItem,
...@@ -76,6 +79,18 @@ class TestResponsesUtils: ...@@ -76,6 +79,18 @@ class TestResponsesUtils:
== 'Hmm, the user has just started with a simple "Hello,"' == 'Hmm, the user has just started with a simple "Hello,"'
) )
tool_call_output = ResponseFunctionToolCallOutputItem(
id="temp_id",
type="function_call_output",
call_id="temp",
output="1234",
status="completed",
)
formatted_item = construct_chat_message_with_tool_call(tool_call_output)
assert formatted_item["role"] == "tool"
assert formatted_item["content"] == "1234"
assert formatted_item["tool_call_id"] == "temp"
item = ResponseReasoningItem( item = ResponseReasoningItem(
id="lol", id="lol",
summary=[], summary=[],
......
...@@ -29,7 +29,6 @@ from openai.types.responses import ( ...@@ -29,7 +29,6 @@ from openai.types.responses import (
ResponseOutputItemAddedEvent, ResponseOutputItemAddedEvent,
ResponseOutputItemDoneEvent, ResponseOutputItemDoneEvent,
ResponsePrompt, ResponsePrompt,
ResponseReasoningItem,
ResponseReasoningTextDeltaEvent, ResponseReasoningTextDeltaEvent,
ResponseReasoningTextDoneEvent, ResponseReasoningTextDoneEvent,
ResponseStatus, ResponseStatus,
...@@ -304,9 +303,7 @@ def get_logits_processors( ...@@ -304,9 +303,7 @@ def get_logits_processors(
return None return None
ResponseInputOutputItem: TypeAlias = ( ResponseInputOutputItem: TypeAlias = ResponseInputItemParam | ResponseOutputItem
ResponseInputItemParam | ResponseReasoningItem | ResponseFunctionToolCall
)
class ResponsesRequest(OpenAIBaseModel): class ResponsesRequest(OpenAIBaseModel):
......
...@@ -10,6 +10,9 @@ from openai.types.chat.chat_completion_message_tool_call_param import ( ...@@ -10,6 +10,9 @@ from openai.types.chat.chat_completion_message_tool_call_param import (
Function as FunctionCallTool, Function as FunctionCallTool,
) )
from openai.types.responses import ResponseFunctionToolCall, ResponseOutputItem from openai.types.responses import ResponseFunctionToolCall, ResponseOutputItem
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_output_message import ResponseOutputMessage
from openai.types.responses.response_reasoning_item import ResponseReasoningItem from openai.types.responses.response_reasoning_item import ResponseReasoningItem
from openai.types.responses.tool import Tool from openai.types.responses.tool import Tool
...@@ -94,6 +97,12 @@ def construct_chat_message_with_tool_call( ...@@ -94,6 +97,12 @@ def construct_chat_message_with_tool_call(
"role": "assistant", "role": "assistant",
"reasoning": reasoning_content, "reasoning": reasoning_content,
} }
elif isinstance(item, ResponseFunctionToolCallOutputItem):
return ChatCompletionToolMessageParam(
role="tool",
content=item.output,
tool_call_id=item.call_id,
)
elif item.get("type") == "function_call_output": elif item.get("type") == "function_call_output":
# Append the function call output as a tool message. # Append the function call output as a tool message.
return ChatCompletionToolMessageParam( return ChatCompletionToolMessageParam(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment