-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
[responsesAPI][8] input/output messages for ResponsesParser #30158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qandrew
wants to merge
6
commits into
vllm-project:main
Choose a base branch
from
qandrew:all-input-output-parsable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+74
−44
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb48da8
initial commit, input / output messages for non harmony responsesAPI
76cad23
unit test
7511fbd
refactor
17fd28c
fix
0d48f5d
Merge branch 'main' into all-input-output-parsable
qandrew fb13011
Merge branch 'main' into all-input-output-parsable
chaunceyjiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,19 @@ | |
| import logging | ||
| from collections.abc import Callable | ||
|
|
||
| from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall | ||
| from openai.types.responses import ResponseFunctionToolCall, ResponseOutputItem | ||
| from openai.types.responses.response_function_tool_call_output_item import ( | ||
| ResponseFunctionToolCallOutputItem, | ||
| ) | ||
| from openai.types.responses.response_input_item import McpCall | ||
| from openai.types.responses.response_output_message import ResponseOutputMessage | ||
| from openai.types.responses.response_output_text import ResponseOutputText | ||
| from openai.types.responses.response_reasoning_item import ( | ||
| Content, | ||
| ResponseReasoningItem, | ||
| ) | ||
|
|
||
| from vllm.entrypoints.constants import MCP_PREFIX | ||
| from vllm.entrypoints.openai.protocol import ResponseInputOutputItem, ResponsesRequest | ||
| from vllm.entrypoints.openai.tool_parsers.abstract_tool_parser import ToolParser | ||
| from vllm.outputs import CompletionOutput | ||
|
|
@@ -111,6 +116,37 @@ def process(self, output: CompletionOutput) -> "ResponsesParser": | |
|
|
||
| return self | ||
|
|
||
| def make_response_output_items_from_parsable_context( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a refactor, no functional changes. |
||
| self, | ||
| ) -> list[ResponseOutputItem]: | ||
| """Given a list of sentences, construct ResponseOutput Items.""" | ||
| response_messages = self.response_messages[self.num_init_messages :] | ||
| output_messages: list[ResponseOutputItem] = [] | ||
| for message in response_messages: | ||
| if not isinstance(message, ResponseFunctionToolCallOutputItem): | ||
| output_messages.append(message) | ||
| else: | ||
| if len(output_messages) == 0: | ||
| raise ValueError( | ||
| "Cannot have a FunctionToolCallOutput before FunctionToolCall." | ||
| ) | ||
| if isinstance(output_messages[-1], ResponseFunctionToolCall): | ||
| mcp_message = McpCall( | ||
| id=f"{MCP_PREFIX}{random_uuid()}", | ||
| arguments=output_messages[-1].arguments, | ||
| name=output_messages[-1].name, | ||
| server_label=output_messages[ | ||
| -1 | ||
| ].name, # TODO: store the server label | ||
| type="mcp_call", | ||
| status="completed", | ||
| output=message.output, | ||
| # TODO: support error output | ||
| ) | ||
| output_messages[-1] = mcp_message | ||
|
|
||
| return output_messages | ||
|
|
||
|
|
||
| def get_responses_parser_for_simple_context( | ||
| *, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parser now converts MCP tool call outputs into
McpCallobjects insidemake_response_output_items_from_parsable_context, but the import here pullsMcpCallfromresponse_input_item. That class models request inputs and (unlike the output version used elsewhere, e.g. harmony_utils) does not carry theoutputfield this method populates, so parsing an MCP call will either raise validation/TypeError or drop the tool output when assembling the response. This should import the output-itemMcpCallto correctly serialize tool results for parsable contexts.Useful? React with 👍 / 👎.