> ## Documentation Index
> Fetch the complete documentation index at: https://siliconflow-4a6a0801.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 推理模型

## 1. 概述

推理模型是基于深度学习的AI系统，通过逻辑推演、知识关联和上下文分析解决复杂任务，典型应用包括数学解题、代码生成、逻辑判断和多步推理场景。这类模型通常具备以下特性：

* 结构化思维：采用思维链（Chain-of-Thought）等技术分解复杂问题
* 知识融合：整合领域知识库与常识推理能力
* 自修正机制：通过验证反馈回路提升结果可靠性
* 多模态处理：部分先进模型支持文本/代码/公式混合输入

## 2. 平台支持推理模型列表

* Qwen 系列：
  * Tongyi-Zhiwen/QwenLong-L1-32B
  * Qwen/Qwen3-30B-A3B
  * Qwen/Qwen3-32B
  * Qwen/Qwen3-14B
  * Qwen/Qwen3-8B
  * Qwen/Qwen3-235B-A22B
  * Qwen/QwQ-32B
* THUDM 系列：
  * THUDM/GLM-Z1-32B-0414
  * THUDM/GLM-Z1-Rumination-32B-0414
  * THUDM/GLM-Z1-9B-0414
* deepseek-ai 系列：
  * Pro/deepseek-ai/DeepSeek-R1
  * deepseek-ai/DeepSeek-R1
  * Pro/deepseek-ai/DeepSeek-R1-0120
  * deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
  * deepseek-ai/DeepSeek-R1-Distill-Qwen-14B
  * deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
  * deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
  * Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
  * Pro/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B

## 3. 使用建议

### 3.1 API 参数

#### 3.1.1 请求参数

* **请求参数**：

  * **最大思维链长度（thinking\_budget）**：模型用于内部推理的 token 数，调节 thinking\_budget 控制回答的思维链长度。
  * **最大回复长度（max\_tokens**）：仅用于限制模型最终输出给用户的回复 token 数，不包含思维链部分。用户可正常配置，控制回复的最大长度。

**最大上下文长度（context\_length）**：包括用户输入长度+思维链长度+输出长度的最大内容长度，非请求参数，不需要用户自己设置。

不同模型支持的最大回复长度、最大思维链长度及最大上下文长度如下表所示：

| 模型                     | 最大回复长度 | 最大思维链长度 | 最大上下文长度 |
| ---------------------- | ------ | ------- | ------- |
| DeepSeek-R1            | 16384  | 32768   | 98304   |
| DeepSeek-R1-Distill 系列 | 16384  | 32768   | 131072  |
| Qwen3 系列               | 8192   | 32768   | 131072  |
| QwQ-32B                | 32768  | 16384   | 131072  |
| GLM-Z1 系列              | 16384  | 32768   | 131072  |

推理模型思维链与回复长度分离后，输出行为将遵循以下规则：

* 若“思考阶段”生成的 `token` 数达到 `thinking_budget`，因 `Qwen3` 系列推理模型原生支持该参数模型将强制停止思维链推理，其他推理模型有可能会继续输出思考内容。
* 若最大回复长度超过 `max_tokens`或上下文长度超过`context_length` 限制，回复内容将进行截断，响应中的 `finish_reason` 字段将标记为 `length`，表示因长度限制终止输出。

#### 3.1.2 返回参数

* **返回参数**:
  * reasoning\_content：思维链内容，与 content 同级。
  * content：最终回答内容

### 3.2 DeepSeek-R1 使用建议

* 将 temperature 设置在 0.5-0.7 范围内（推荐值为 0.6），以防止无限循环或不连贯的输出。

* 将 top\_p 的值设置在 0.95。

* 避免添加系统提示,所有指令应包含在用户提示中。

* 对于数学问题，建议在提示中包含一个指令，例如：“请逐步推理，并将最终答案写在 \boxed{} 中。”

* 在评估模型性能时，建议进行多次测试并平均结果。

{/*
  - 使用特定提示词用于文件上传和网页搜索，以提供更好的用户体验。

      * 对于文件上传，请按照模板创建提示，其中`{file_name}`、`{file_content}` 和 `{question}` 是参数。

      ```bash
      file_template = \
      """[file name]: {file_name}
      [file content begin]
      {file_content}
      [file content end]
      {question}"""
      ```

      * 对于网页搜索，`{search_results}`、`{cur_data}` 和 `{question}`是参数。
      
          * 对于中文查询，使用提示:

      ```bash
      search_answer_zh_template = \
      '''# 以下内容是基于用户发送的消息的搜索结果:
      {search_results}
      在我给你的搜索结果中，每个结果都是[webpage X begin]...[webpage X end]格式的，X代表每篇文章的数字索引。请在适当的情况下在句子末尾引用上下文。请按照引用编号[citation:X]的格式在答案中对应部分引用上下文。如果一句话源自多个上下文，请列出所有相关的引用编号，例如[citation:3][citation:5]，切记不要将引用集中在最后返回引用编号，而是在答案对应部分列出。
      在回答时，请注意以下几点：
      - 今天是{cur_date}。
      - 并非搜索结果的所有内容都与用户的问题密切相关，你需要结合问题，对搜索结果进行甄别、筛选。
      - 对于列举类的问题（如列举所有航班信息），尽量将答案控制在10个要点以内，并告诉用户可以查看搜索来源、获得完整信息。优先提供信息完整、最相关的列举项；如非必要，不要主动告诉用户搜索结果未提供的内容。
      - 对于创作类的问题（如写论文），请务必在正文的段落中引用对应的参考编号，例如[citation:3][citation:5]，不能只在文章末尾引用。你需要解读并概括用户的题目要求，选择合适的格式，充分利用搜索结果并抽取重要信息，生成符合用户要求、极具思想深度、富有创造力与专业性的答案。你的创作篇幅需要尽可能延长，对于每一个要点的论述要推测用户的意图，给出尽可能多角度的回答要点，且务必信息量大、论述详尽。
      - 如果回答很长，请尽量结构化、分段落总结。如果需要分点作答，尽量控制在5个点以内，并合并相关的内容。
      - 对于客观类的问答，如果问题的答案非常简短，可以适当补充一到两句相关信息，以丰富内容。
      - 你需要根据用户要求和回答内容选择合适、美观的回答格式，确保可读性强。
      - 你的回答应该综合多个相关网页来回答，不能重复引用一个网页。
      - 除非用户要求，否则你回答的语言需要和用户提问的语言保持一致。

      # 用户消息为：
      {question}'''
      ```

          * 对于英文查询，使用提示：

      ```bash
      search_answer_en_template = \
      '''# The following contents are the search results related to the user's message:
      {search_results}
      In the search results I provide to you, each result is formatted as [webpage X begin]...[webpage X end], where X represents the numerical index of each article. Please cite the context at the end of the relevant sentence when appropriate. Use the citation format [citation:X] in the corresponding part of your answer. If a sentence is derived from multiple contexts, list all relevant citation numbers, such as [citation:3][citation:5]. Be sure not to cluster all citations at the end; instead, include them in the corresponding parts of the answer.
      When responding, please keep the following points in mind:
      - Today is {cur_date}.
      - Not all content in the search results is closely related to the user's question. You need to evaluate and filter the search results based on the question.
      - For listing-type questions (e.g., listing all flight information), try to limit the answer to 10 key points and inform the user that they can refer to the search sources for complete information. Prioritize providing the most complete and relevant items in the list. Avoid mentioning content not provided in the search results unless necessary.
      - For creative tasks (e.g., writing an essay), ensure that references are cited within the body of the text, such as [citation:3][citation:5], rather than only at the end of the text. You need to interpret and summarize the user's requirements, choose an appropriate format, fully utilize the search results, extract key information, and generate an answer that is insightful, creative, and professional. Extend the length of your response as much as possible, addressing each point in detail and from multiple perspectives, ensuring the content is rich and thorough.
      - If the response is lengthy, structure it well and summarize it in paragraphs. If a point-by-point format is needed, try to limit it to 5 points and merge related content.
      - For objective Q&A, if the answer is very brief, you may add one or two related sentences to enrich the content.
      - Choose an appropriate and visually appealing format for your response based on the user's requirements and the content of the answer, ensuring strong readability.
      - Your answer should synthesize information from multiple relevant webpages and avoid repeatedly citing the same webpage.
      - Unless the user requests otherwise, your response should be in the same language as the user's question.

      # The user's message is:
      {question}'''
      ```*/}

## 4. openai请求示例

### 4.1 流式输出请求

```python
from openai import OpenAI

url = 'https://api.siliconflow.cn/v1/'
api_key = 'your api_key'

client = OpenAI(
    base_url=url,
    api_key=api_key
)

# 发送带有流式输出的请求
content = ""
reasoning_content=""
messages = [
    {"role": "user", "content": "奥运会的传奇名将有哪些？"}
]
response = client.chat.completions.create(
    model="Pro/deepseek-ai/DeepSeek-R1",
    messages=messages,
    stream=True,  # 启用流式输出
    max_tokens=4096,
    extra_body={
        "thinking_budget": 1024
    }
)
# 逐步接收并处理响应
for chunk in response:
    if chunk.choices[0].delta.content:
        content += chunk.choices[0].delta.content
    if chunk.choices[0].delta.reasoning_content:
        reasoning_content += chunk.choices[0].delta.reasoning_content

# Round 2
messages.append({"role": "assistant", "content": content})
messages.append({'role': 'user', 'content': "继续"})
response = client.chat.completions.create(
    model="Pro/deepseek-ai/DeepSeek-R1",
    messages=messages,
    stream=True
)
```

### 4.2 非流式输出请求

```python
from openai import OpenAI
url = 'https://api.siliconflow.cn/v1/'
api_key = 'your api_key'

client = OpenAI(
    base_url=url,
    api_key=api_key
)

# 发送非流式输出的请求
messages = [
    {"role": "user", "content": "奥运会的传奇名将有哪些？"}
]
response = client.chat.completions.create(
    model="Pro/deepseek-ai/DeepSeek-R1",
    messages=messages,
    stream=False, 
    max_tokens=4096,
    extra_body={
        "thinking_budget": 1024
    }
)
content = response.choices[0].message.content
reasoning_content = response.choices[0].message.reasoning_content

# Round 2
messages.append({"role": "assistant", "content": content})
messages.append({'role': 'user', 'content': "继续"})
response = client.chat.completions.create(
    model="Pro/deepseek-ai/DeepSeek-R1",
    messages=messages,
    stream=False
)
```

## 5. 注意事项

* API 密钥：请确保使用正确的 API 密钥进行身份验证。
* 流式输出：流式输出适用于需要逐步接收响应的场景，而非流式输出则适用于一次性获取完整响应的场景。

{/* - 上下文管理：在每一轮对话中，模型输出的思维链内容不会被拼接到下一轮对话的上下文中，因此需要手动管理上下文。*/}

## 6. 常见问题

* 如何获取 API 密钥？

  请访问 [SiliconFlow](https://cloud.siliconflow.cn/) 注册并获取 API 密钥。
* 如何处理超长文本？

  可以通过调整 max\_tokens 参数来控制输出的长度，但请注意最大长度为 16K。
