-
-
Notifications
You must be signed in to change notification settings - Fork 15k
[Frontend]: minimax_m2 supports structural_tag #32232
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
Draft
chaunceyjiang
wants to merge
3
commits into
vllm-project:main
Choose a base branch
from
chaunceyjiang:minimax_structural_tag
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.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| DeltaToolCall, | ||
| ExtractedToolCallInformation, | ||
| FunctionCall, | ||
| StructuralTagResponseFormat, | ||
| ToolCall, | ||
| ) | ||
| from vllm.logger import init_logger | ||
|
|
@@ -24,6 +25,33 @@ | |
| ) | ||
|
|
||
| logger = init_logger(__name__) | ||
| MINIMAX_M2_TOOL_CALLING_SCHEMA = { | ||
| "type": "structural_tag", | ||
| "format": { | ||
| "type": "triggered_tags", | ||
| "triggers": ["<minimax:tool_call>"], | ||
| "tags": [ | ||
| { | ||
| "begin": "<minimax:tool_call>", | ||
| "content": { | ||
| "type": "tags_with_separator", | ||
| "separator": "\n", | ||
| "tags": [ | ||
| # { | ||
| # "type": "tag", | ||
| # "begin": '<invoke name="get_current_weather">', | ||
| # "end": "</invoke>", | ||
| # "content": {"type": "any_text"}, | ||
| # }, | ||
| ], | ||
| "at_least_one": True, | ||
| "stop_after_first": False, | ||
| }, | ||
| "end": "</minimax:tool_call>", | ||
| } | ||
| ], | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| class MinimaxM2ToolParser(ToolParser): | ||
|
|
@@ -359,6 +387,9 @@ def extract_tool_calls( | |
| request: ChatCompletionRequest, | ||
| ) -> ExtractedToolCallInformation: | ||
| """Extract tool calls from complete model output (non-streaming).""" | ||
| return ExtractedToolCallInformation( | ||
| tools_called=False, tool_calls=[], content=model_output | ||
| ) | ||
|
Comment on lines
+390
to
+392
Contributor
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. |
||
| # Quick check | ||
| if self.tool_call_start_token not in model_output: | ||
| return ExtractedToolCallInformation( | ||
|
|
@@ -774,3 +805,52 @@ def extract_tool_calls_streaming( | |
| ) | ||
|
|
||
| return None | ||
|
|
||
| def prepare_structured_tags( | ||
| self, request: ChatCompletionRequest | ||
| ) -> ChatCompletionRequest | None: | ||
| """Prepare structured tags for MiniMax M2 tool calls.""" | ||
| if not request.tools or len(request.tools) == 0: | ||
| return None | ||
|
|
||
| # Set the structured tags for tool calls | ||
| structured_tags = MINIMAX_M2_TOOL_CALLING_SCHEMA.copy() | ||
| for tool in request.tools: | ||
| if hasattr(tool, "function") and hasattr(tool.function, "name"): | ||
| func_tag = { | ||
| "type": "tag", | ||
| "begin": f'<invoke name="{tool.function.name}">', | ||
| "end": "</invoke>", | ||
| "content": { | ||
| "type": "tags_with_separator", | ||
| "separator": "\n", | ||
| "tags": [], | ||
| "at_least_one": False, | ||
| "stop_after_first": False, | ||
| }, | ||
| } | ||
| # Add parameters | ||
| if ( | ||
| hasattr(tool.function, "parameters") | ||
| and isinstance(tool.function.parameters, dict) | ||
| and "properties" in tool.function.parameters | ||
| ): | ||
| for param_name in tool.function.parameters["properties"]: | ||
| param_tag = { | ||
| "type": "tag", | ||
| "begin": f'<parameter name="{param_name}">', | ||
| "end": "</parameter>", | ||
| # "content": { | ||
| # "type": "const_string", | ||
| # "value": "...", | ||
| # }, # debug | ||
| "content": {"type": "any_text"}, | ||
|
Collaborator
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. |
||
| } | ||
| func_tag["content"]["tags"].append(param_tag) | ||
|
|
||
| structured_tags["format"]["tags"][0]["content"]["tags"].append(func_tag) | ||
| request.response_format = StructuralTagResponseFormat( | ||
| type="structural_tag", format=structured_tags["format"] | ||
| ) | ||
| print(structured_tags) | ||
|
Contributor
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. |
||
| return request | ||
Oops, something went wrong.
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.
These appear to be debug
printstatements. They should be removed before merging to avoid polluting production logs.