mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-06-02 19:51:18 +08:00
Update MiniMax-M2 ToolCall and add MiniMax-M2.1 in Docs (#31083)
Signed-off-by: xuebi <xuebi@minimaxi.com> Co-authored-by: xuebi <xuebi@minimaxi.com>
This commit is contained in:
parent
cf8eed7bef
commit
c02a2705f9
@ -418,7 +418,7 @@ th {
|
|||||||
| `MiMoV2FlashForCausalLM` | MiMoV2Flash | `XiaomiMiMo/MiMo-V2-Flash`, etc. | ︎| ✅︎ |
|
| `MiMoV2FlashForCausalLM` | MiMoV2Flash | `XiaomiMiMo/MiMo-V2-Flash`, etc. | ︎| ✅︎ |
|
||||||
| `MiniCPMForCausalLM` | MiniCPM | `openbmb/MiniCPM-2B-sft-bf16`, `openbmb/MiniCPM-2B-dpo-bf16`, `openbmb/MiniCPM-S-1B-sft`, etc. | ✅︎ | ✅︎ |
|
| `MiniCPMForCausalLM` | MiniCPM | `openbmb/MiniCPM-2B-sft-bf16`, `openbmb/MiniCPM-2B-dpo-bf16`, `openbmb/MiniCPM-S-1B-sft`, etc. | ✅︎ | ✅︎ |
|
||||||
| `MiniCPM3ForCausalLM` | MiniCPM3 | `openbmb/MiniCPM3-4B`, etc. | ✅︎ | ✅︎ |
|
| `MiniCPM3ForCausalLM` | MiniCPM3 | `openbmb/MiniCPM3-4B`, etc. | ✅︎ | ✅︎ |
|
||||||
| `MiniMaxM2ForCausalLM` | MiniMax-M2 |`MiniMaxAI/MiniMax-M2`, etc. | | ✅︎ |
|
| `MiniMaxM2ForCausalLM` | MiniMax-M2, MiniMax-M2.1 |`MiniMaxAI/MiniMax-M2`, etc. | | ✅︎ |
|
||||||
| `MistralForCausalLM` | Ministral-3, Mistral, Mistral-Instruct | `mistralai/Ministral-3-3B-Instruct-2512`, `mistralai/Mistral-7B-v0.1`, `mistralai/Mistral-7B-Instruct-v0.1`, etc. | ✅︎ | ✅︎ |
|
| `MistralForCausalLM` | Ministral-3, Mistral, Mistral-Instruct | `mistralai/Ministral-3-3B-Instruct-2512`, `mistralai/Mistral-7B-v0.1`, `mistralai/Mistral-7B-Instruct-v0.1`, etc. | ✅︎ | ✅︎ |
|
||||||
| `MistralLarge3ForCausalLM` | Mistral-Large-3-675B-Base-2512, Mistral-Large-3-675B-Instruct-2512 | `mistralai/Mistral-Large-3-675B-Base-2512`, `mistralai/Mistral-Large-3-675B-Instruct-2512`, etc. | ✅︎ | ✅︎ |
|
| `MistralLarge3ForCausalLM` | Mistral-Large-3-675B-Base-2512, Mistral-Large-3-675B-Instruct-2512 | `mistralai/Mistral-Large-3-675B-Base-2512`, `mistralai/Mistral-Large-3-675B-Instruct-2512`, etc. | ✅︎ | ✅︎ |
|
||||||
| `MixtralForCausalLM` | Mixtral-8x7B, Mixtral-8x7B-Instruct | `mistralai/Mixtral-8x7B-v0.1`, `mistralai/Mixtral-8x7B-Instruct-v0.1`, `mistral-community/Mixtral-8x22B-v0.1`, etc. | ✅︎ | ✅︎ |
|
| `MixtralForCausalLM` | Mixtral-8x7B, Mixtral-8x7B-Instruct | `mistralai/Mixtral-8x7B-v0.1`, `mistralai/Mixtral-8x7B-Instruct-v0.1`, `mistral-community/Mixtral-8x22B-v0.1`, etc. | ✅︎ | ✅︎ |
|
||||||
|
|||||||
@ -138,37 +138,167 @@ class MinimaxM2ToolParser(ToolParser):
|
|||||||
return name_str
|
return name_str
|
||||||
|
|
||||||
def _convert_param_value(self, value: str, param_type: str) -> Any:
|
def _convert_param_value(self, value: str, param_type: str) -> Any:
|
||||||
"""Convert parameter value to the correct type."""
|
"""Convert parameter value to the correct type (legacy single-type version)."""
|
||||||
|
return self._convert_param_value_with_types(value, [param_type])
|
||||||
|
|
||||||
|
def _extract_types_from_schema(self, schema: Any) -> list[str]:
|
||||||
|
"""
|
||||||
|
Extract all possible types from a JSON schema definition.
|
||||||
|
Handles anyOf, oneOf, allOf, type arrays, and enum fields.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
schema: The JSON schema definition for a parameter
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of type strings (e.g., ["string", "integer", "null"])
|
||||||
|
"""
|
||||||
|
if schema is None:
|
||||||
|
return ["string"]
|
||||||
|
|
||||||
|
if not isinstance(schema, dict):
|
||||||
|
return ["string"]
|
||||||
|
|
||||||
|
types: set[str] = set()
|
||||||
|
|
||||||
|
# Handle direct "type" field
|
||||||
|
if "type" in schema:
|
||||||
|
type_value = schema["type"]
|
||||||
|
if isinstance(type_value, str):
|
||||||
|
types.add(type_value)
|
||||||
|
elif isinstance(type_value, list):
|
||||||
|
for t in type_value:
|
||||||
|
if isinstance(t, str):
|
||||||
|
types.add(t)
|
||||||
|
|
||||||
|
# Handle enum - infer types from enum values
|
||||||
|
if "enum" in schema and isinstance(schema["enum"], list) and schema["enum"]:
|
||||||
|
for value in schema["enum"]:
|
||||||
|
if value is None:
|
||||||
|
types.add("null")
|
||||||
|
elif isinstance(value, bool):
|
||||||
|
types.add("boolean")
|
||||||
|
elif isinstance(value, int):
|
||||||
|
types.add("integer")
|
||||||
|
elif isinstance(value, float):
|
||||||
|
types.add("number")
|
||||||
|
elif isinstance(value, str):
|
||||||
|
types.add("string")
|
||||||
|
elif isinstance(value, list):
|
||||||
|
types.add("array")
|
||||||
|
elif isinstance(value, dict):
|
||||||
|
types.add("object")
|
||||||
|
|
||||||
|
# Handle anyOf, oneOf, allOf - recursively extract types
|
||||||
|
for choice_field in ("anyOf", "oneOf", "allOf"):
|
||||||
|
if choice_field in schema and isinstance(schema[choice_field], list):
|
||||||
|
for choice in schema[choice_field]:
|
||||||
|
extracted = self._extract_types_from_schema(choice)
|
||||||
|
types.update(extracted)
|
||||||
|
|
||||||
|
# If no types found, default to string
|
||||||
|
if not types:
|
||||||
|
return ["string"]
|
||||||
|
|
||||||
|
return list(types)
|
||||||
|
|
||||||
|
def _convert_param_value_with_types(
|
||||||
|
self, value: str, param_types: list[str]
|
||||||
|
) -> Any:
|
||||||
|
"""
|
||||||
|
Convert parameter value to the correct type based on a list of possible types.
|
||||||
|
Tries each type in order until one succeeds.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value: The string value to convert
|
||||||
|
param_types: List of possible type strings
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The converted value
|
||||||
|
"""
|
||||||
if value.lower() == "null":
|
if value.lower() == "null":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
param_type = param_type.lower()
|
# Normalize types
|
||||||
if param_type in ["string", "str", "text"]:
|
normalized_types = [t.lower() for t in param_types]
|
||||||
|
|
||||||
|
# Try null first if it's in the list
|
||||||
|
if "null" in normalized_types or value.lower() in ("null", "none", "nil"):
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Try each type in order of preference (most specific first, string as fallback)
|
||||||
|
# Priority: integer > number > boolean > object > array > string
|
||||||
|
type_priority = [
|
||||||
|
"integer",
|
||||||
|
"int",
|
||||||
|
"number",
|
||||||
|
"float",
|
||||||
|
"boolean",
|
||||||
|
"bool",
|
||||||
|
"object",
|
||||||
|
"array",
|
||||||
|
"string",
|
||||||
|
"str",
|
||||||
|
"text",
|
||||||
|
]
|
||||||
|
|
||||||
|
for param_type in type_priority:
|
||||||
|
if param_type not in normalized_types:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if param_type in ["string", "str", "text"]:
|
||||||
|
return value
|
||||||
|
elif param_type in ["integer", "int"]:
|
||||||
|
try:
|
||||||
|
return int(value)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
continue
|
||||||
|
elif param_type in ["number", "float"]:
|
||||||
|
try:
|
||||||
|
val = float(value)
|
||||||
|
return val if val != int(val) else int(val)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
continue
|
||||||
|
elif param_type in ["boolean", "bool"]:
|
||||||
|
lower_val = value.lower().strip()
|
||||||
|
if lower_val in ["true", "1", "yes", "on"]:
|
||||||
|
return True
|
||||||
|
elif lower_val in ["false", "0", "no", "off"]:
|
||||||
|
return False
|
||||||
|
continue
|
||||||
|
elif param_type in ["object", "array"]:
|
||||||
|
try:
|
||||||
|
return json.loads(value)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Fallback: try JSON parse, then return as string
|
||||||
|
try:
|
||||||
|
return json.loads(value)
|
||||||
|
except json.JSONDecodeError:
|
||||||
return value
|
return value
|
||||||
elif param_type in ["integer", "int"]:
|
|
||||||
try:
|
def _get_param_types_from_config(
|
||||||
return int(value)
|
self, param_name: str, param_config: dict
|
||||||
except (ValueError, TypeError):
|
) -> list[str]:
|
||||||
return value
|
"""
|
||||||
elif param_type in ["number", "float"]:
|
Get parameter types from parameter configuration.
|
||||||
try:
|
Handles anyOf, oneOf, allOf, and direct type definitions.
|
||||||
val = float(value)
|
|
||||||
return val if val != int(val) else int(val)
|
Args:
|
||||||
except (ValueError, TypeError):
|
param_name: The name of the parameter
|
||||||
return value
|
param_config: The properties dict from the tool schema
|
||||||
elif param_type in ["boolean", "bool"]:
|
|
||||||
return value.lower() in ["true", "1"]
|
Returns:
|
||||||
elif param_type in ["object", "array"]:
|
List of type strings
|
||||||
try:
|
"""
|
||||||
return json.loads(value)
|
if param_name not in param_config:
|
||||||
except json.JSONDecodeError:
|
return ["string"]
|
||||||
return value
|
|
||||||
else:
|
param_schema = param_config[param_name]
|
||||||
# Try JSON parse first, fallback to string
|
if not isinstance(param_schema, dict):
|
||||||
try:
|
return ["string"]
|
||||||
return json.loads(value)
|
|
||||||
except json.JSONDecodeError:
|
return self._extract_types_from_schema(param_schema)
|
||||||
return value
|
|
||||||
|
|
||||||
def _parse_single_invoke(
|
def _parse_single_invoke(
|
||||||
self, invoke_str: str, tools: list | None
|
self, invoke_str: str, tools: list | None
|
||||||
@ -207,17 +337,11 @@ class MinimaxM2ToolParser(ToolParser):
|
|||||||
if param_value.endswith("\n"):
|
if param_value.endswith("\n"):
|
||||||
param_value = param_value[:-1]
|
param_value = param_value[:-1]
|
||||||
|
|
||||||
# Get parameter type
|
# Get parameter types (supports anyOf/oneOf/allOf)
|
||||||
param_type = "string"
|
param_type = self._get_param_types_from_config(param_name, param_config)
|
||||||
if (
|
|
||||||
param_name in param_config
|
|
||||||
and isinstance(param_config[param_name], dict)
|
|
||||||
and "type" in param_config[param_name]
|
|
||||||
):
|
|
||||||
param_type = param_config[param_name]["type"]
|
|
||||||
|
|
||||||
# Convert value
|
# Convert value
|
||||||
param_dict[param_name] = self._convert_param_value(
|
param_dict[param_name] = self._convert_param_value_with_types(
|
||||||
param_value, param_type
|
param_value, param_type
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -593,7 +717,7 @@ class MinimaxM2ToolParser(ToolParser):
|
|||||||
# Store raw value for later processing
|
# Store raw value for later processing
|
||||||
self.accumulated_params[self.current_param_name] = param_value
|
self.accumulated_params[self.current_param_name] = param_value
|
||||||
|
|
||||||
# Get parameter configuration for type conversion
|
# Get parameter configuration with anyOf support
|
||||||
param_config = {}
|
param_config = {}
|
||||||
if self.streaming_request and self.streaming_request.tools:
|
if self.streaming_request and self.streaming_request.tools:
|
||||||
for tool in self.streaming_request.tools:
|
for tool in self.streaming_request.tools:
|
||||||
@ -610,17 +734,12 @@ class MinimaxM2ToolParser(ToolParser):
|
|||||||
param_config = params["properties"]
|
param_config = params["properties"]
|
||||||
break
|
break
|
||||||
|
|
||||||
# Get parameter type
|
# Get parameter types (supports anyOf/oneOf/allOf)
|
||||||
param_type = "string"
|
param_type = self._get_param_types_from_config(
|
||||||
if (
|
self.current_param_name, param_config
|
||||||
self.current_param_name in param_config
|
)
|
||||||
and isinstance(param_config[self.current_param_name], dict)
|
|
||||||
and "type" in param_config[self.current_param_name]
|
|
||||||
):
|
|
||||||
param_type = param_config[self.current_param_name]["type"]
|
|
||||||
|
|
||||||
# Convert param value to appropriate type
|
converted_value = self._convert_param_value_with_types(
|
||||||
converted_value = self._convert_param_value(
|
|
||||||
param_value, param_type
|
param_value, param_type
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user