← 返回主页

🧠 Deepseek Reasoning

推理模型对话格式 - 带思维链的智能推理

📝 简介

Deepseek-reasoner 是 DeepSeek 推出的推理模型。在输出最终回答之前,模型会先输出一段思维链内容,以提升最终答案的准确性。API 向用户开放 deepseek-reasoner 思维链的内容,以供用户查看、展示、蒸馏使用。

🔬 推理模型特点

🔗 接口端点

POST/v1/chat/completions

使用 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
  }
}

🔍 响应字段说明

  • reasoning_content - 模型的完整推理过程,展示了思考步骤
  • content - 基于推理得出的简洁最终答案
  • finish_reason - 生成结束的原因(通常为 "stop")
📡 流式推理响应 ✅
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 字段的最终答案
  • 实时展示 - 用户可以实时看到模型的思考过程

🚀 使用建议