使用 MiMo 的 thinking.type
MiMo 使用 thinking.type 开启或关闭思考。mimo-v2.6-pro 默认开启思考,可显式设置 enabled 或 disabled;输出长度使用 max_completion_tokens,额度包含推理和最终回答。
确认目标 MiMo 模型适用本文
本文的 mimo-v2.6-pro 示例适用于 GenStudio 默认 OpenAI 兼容 Chat Completions 接口(/maas/v1/chat/completions)。默认、显式开启和显式关闭思考均已在非流式与流式请求中验证。使用其他模型 ID、M×N 路径或其他协议时,应分别验证参数和响应。
设置当前请求的 thinking.type
当前请求开启思考时使用 thinking.type: "enabled"。以下 Python 示例使用 OpenAI SDK,并为推理和最终回答合计预留 2048 个 token。
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["API_KEY"],
base_url="https://cloud.infini-ai.com/maas/v1",
)
response = client.chat.completions.create(
model="mimo-v2.6-pro",
messages=[{
"role": "user",
"content": "A warehouse has 17 boxes with 23 parts each and sends out 58 parts. How many parts remain? Reply with only the integer.",
}],
max_completion_tokens=2048,
extra_body={"thinking": {"type": "enabled"}},
)关闭思考时使用:
extra_body = {"thinking": {"type": "disabled"}}省略 thinking 时,mimo-v2.6-pro 默认开启思考。开启思考的上述示例应返回 reasoning_content 和最终回答 333。关闭思考后,已验证的两种响应模式均未返回推理内容;应用仍需单独校验最终答案。
max_completion_tokens 同时包含推理 token 和可见输出 token。如果响应以 finish_reason: "length" 结束,应将其视为不完整结果,并调整额度。不要在同一请求中同时设置 max_tokens 和 max_completion_tokens。
用 curl 验证 thinking.type 请求体
先用 curl 确认请求体中已经传入 MiMo 的 thinking.type。运行前先在当前终端设置 API_KEY 环境变量。以下 curl 命令适用于 bash/zsh 等 POSIX 风格 Shell(macOS/Linux、WSL、Git Bash)。如果使用 Windows PowerShell 或 CMD,请按对应 Shell 的语法调整命令。
curl --request POST \
--url "https://cloud.infini-ai.com/maas/v1/chat/completions" \
--header "Accept: application/json, text/event-stream" \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"model": "mimo-v2.6-pro",
"messages": [
{
"role": "user",
"content": "A warehouse has 17 boxes with 23 parts each and sends out 58 parts. How many parts remain? Reply with only the integer."
}
],
"max_completion_tokens": 2048,
"thinking": {
"type": "enabled"
}
}'以下终端录制使用 mimo-v2.5-pro 和当时的 max_tokens 参数,演示请求与响应的查看方式。调用 mimo-v2.6-pro 时,请使用上方请求中的模型 ID 和 max_completion_tokens。
终端录制
用 curl 验证 MiMo thinking.type
适用于验证 MiMo 推理开关字段是否按预期传入。
点击播放,无输出等待最多 1 秒。文字较小时,可放大阅读。
读取 MiMo 的 reasoning_content
如果 MiMo 输出了思考过程,可以从 reasoning_content 读取。SDK 类型可能不声明该字段,应使用动态访问。
message = response.choices[0].message
reasoning = getattr(message, "reasoning_content", None)
if reasoning:
print(reasoning)
print(message.content)流式响应中读取 delta.reasoning_content。
工具调用后保留 reasoning_content
Agent 或工具调用流程中,如果 assistant 消息带有 tool_calls 和 reasoning_content,继续请求时应一起回传。mimo-v2.6-pro 已验证在非流式与流式请求中回传实际返回的推理内容和工具调用,并继续生成回答。
assistant_message = {
"role": "assistant",
"content": response.choices[0].message.content or "",
"tool_calls": [
{
"id": tool_call.id,
"type": "function",
"function": {
"name": tool_call.function.name,
"arguments": tool_call.function.arguments,
},
}
for tool_call in response.choices[0].message.tool_calls
],
}
reasoning = getattr(response.choices[0].message, "reasoning_content", None)
if reasoning:
assistant_message["reasoning_content"] = reasoning
messages.append(assistant_message)不要只回传工具调用参数而丢掉同一条 assistant 消息上的推理字段。追加工具结果时,tool_call_id 必须匹配返回的工具调用 ID;流式请求应先拼接完整的推理内容和工具调用,再写入历史消息。
把 reasoning_effort 当作接受性验证
Xiaomi 的 OpenAI 兼容接口文档没有定义 reasoning_effort。mimo-v2.5-pro 的历史验证曾接受 low、medium 和 high;mimo-v2.6-pro 在非流式请求中也接受了这三个值,一个无效测试值返回 HTTP 400。
这些结果只说明请求的接受情况,不能证明三个值对应不同推理强度,也不能据此判断质量、延迟或 token 用量会发生变化。业务接入使用 thinking.type 控制开关,不依赖 reasoning_effort 调节推理强度。
修复工具调用历史缺字段导致的 400 错误
工具调用后的 400 通常来自历史消息不完整。排查时检查以下内容:
- 上一条 assistant 消息的
tool_calls是否完整。 - tool 消息的
tool_call_id是否匹配上一条 assistant 消息。 - 如果上一条 assistant 消息返回过
reasoning_content,是否被序列化保留。 - 如果某一轮关闭思考且没有推理字段,是否错误补写了人工推理。
先修正消息历史,再调整 prompt 或模型参数。