本文档概述了在使用 DeepSeek-R1 系列模型时构建有效提示的最佳实践。遵循这些指南将有助于确保在各种任务中都能获得最佳性能,尤其是在推理、数学和代码生成方面。有关访问模型的信息,请参阅 模型访问,有关本地部署说明,请参阅 本地部署。
DeepSeek-R1 模型在提示结构方面有特定的偏好,以实现最佳性能。以下指南适用于 DeepSeek-R1 系列中的所有模型,包括经过蒸馏的版本。
| 参数 | 建议 | 备注 |
|---|---|---|
| 温度 | 0.5-0.7(推荐 0.6) | 防止无休止的重复或不连贯的输出 |
| 系统提示 | 避免使用 | 所有指令都应包含在用户提示中 |
| 评估 | 进行多次测试 | 平均结果以进行更准确的性能评估 |
| 响应格式 | 强制执行思考模式 | 以 `\nFinal Answer"` 开头回复 |
end
"Reasoning Prompt Structure" --> "Model Processing"
Sources: <FileRef file-url="https://github.com/deepseek-ai/DeepSeek-R1/blob/0cf78561/README.md#L195-L196" min=195 max=196 file-path="README.md">Hii</FileRef>
## 3. Special Use Case Templates
The DeepSeek-R1 models support specialized prompting templates for specific use cases, such as file upload and web search.
### 3.1 File Upload Template
When working with file uploads, use the following template structure:
[文件内容开始] {file_content} [文件内容结束] {question}
Where:
- `{file_name}` is the name of the uploaded file
- `{file_content}` is the content of the file
- `{question}` is the user's question about the file
Sources: <FileRef file-url="https://github.com/deepseek-ai/DeepSeek-R1/blob/0cf78561/README.md#L202-L209" min=202 max=209 file-path="README.md">Hii</FileRef>
### 3.2 Web Search Templates
The DeepSeek-R1 models use different templates for web search queries depending on the language.
#### Chinese Web Search Template
A specialized template for handling web search in Chinese, including citation formatting and response structure guidelines.
#### English Web Search Template
A structured template for English web search queries, with similar citation formatting and response structure guidelines.
Sources: <FileRef file-url="https://github.com/deepseek-ai/DeepSeek-R1/blob/0cf78561/README.md#L212-L254" min=212 max=254 file-path="README.md">Hii</FileRef>
## 4. Troubleshooting Common Issues
### 4.1 Repetitive or Incoherent Outputs
If the model produces repetitive or incoherent outputs:
1. Verify that the temperature is set between 0.5-0.7 (preferably 0.6)
2. Ensure all instructions are in the user prompt (not in a system prompt)
3. For complex reasoning tasks, explicitly instruct the model to think step by step
```mermaid
flowchart TD
A[Repetitive/Incoherent Output] --> B{Temperature set correctly?}
B -->|No| C[Adjust temperature to 0.6]
B -->|Yes| D{Using system prompt?}
D -->|Yes| E[Move instructions to user prompt]
D -->|No| F{Complex reasoning task?}
F -->|Yes| G[Add step-by-step directive]
F -->|No| H[Clarify instructions]
C --> I[Test with new prompt]
E --> I
G --> I
H --> I
来源: README.md187-196
如果模型绕过了思考模式
来源: README.md195-196
在基准测试中评估 DeepSeek-R1 模型或比较性能时
来源: README.md101-103
DeepSeek-R1 模型在提示偏好方面与许多其他语言模型不同,尤其是在系统提示和推理模式的处理方式上。
来源: README.md187-196
这种专门的提示方法旨在利用 DeepSeek-R1 系列模型的先进推理能力,这些模型是使用强化学习技术专门训练以提高推理性能的。