推理模型对话格式 - 带思维链的智能推理
Deepseek-reasoner 是 DeepSeek 推出的推理模型。在输出最终回答之前,模型会先输出一段思维链内容,以提升最终答案的准确性。API 向用户开放 deepseek-reasoner 思维链的内容,以供用户查看、展示、蒸馏使用。
使用 deepseek-reasoner 模型创建带有推理过程的对话补全。
| 参数名 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | - | 必须设置为 "deepseek-reasoner" |
| messages | array | 是 | - | 对话消息数组 |
| max_tokens | integer | 否 | 4096 | 最大生成token数 |
| temperature | number | 否 | 1.0 | 随机性控制 (0-2) |
| stream | boolean | 否 | false | 是否流式输出 |
| top_p | number | 否 | 1.0 | 核采样参数 |
deepseek-reasoner 模型的响应包含两个关键字段:
reasoning_content - 模型的思维链推理过程content - 基于推理得出的最终答案curl https://rootapiai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ROOTAPI_API_KEY" \
-d '{
"model": "deepseek-reasoner",
"messages": [
{
"role": "user",
"content": "9.11 and 9.8, which is greater?"
}
],
"max_tokens": 4096
}'
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "deepseek-reasoner",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "让我一步步思考:\n1. 我们需要比较9.11和9.8的大小\n2. 两个数都是小数,我们可以直接比较\n3. 9.8 = 9.80\n4. 9.11 < 9.80\n5. 所以9.8更大",
"content": "9.8 is greater than 9.11."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 15,
"total_tokens": 25
}
}
curl https://rootapiai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ROOTAPI_API_KEY" \
-d '{
"model": "deepseek-reasoner",
"messages": [
{
"role": "user",
"content": "9.11 and 9.8, which is greater?"
}
],
"stream": true
}'
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"role":"assistant","reasoning_content":"让我"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"reasoning_content":"一步步"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"reasoning_content":"思考:"},"finish_reason":null}]}
// ... 更多思维链内容 ...
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"content":"9.8"},"finish_reason":null}]}
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{"content":" is greater"},"finish_reason":null}]}
// ... 更多最终答案内容 ...
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"deepseek-reasoner","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
在流式模式下,推理内容和最终答案会分别逐步输出:
reasoning_content 字段的内容content 字段的最终答案