DeepSeek 网摘deepseek.wang
EN
📄 查看英文原文

工具 · 2026-04-25 · 机器翻译,仅供参考

DeepSeek 提示模板:V4 实践者图书馆

<文章>
Tools·April 25, 2026·By DS Guide Editorial
DeepSeek prompt-templates card showing the four facts about the practitioner library: twelve copy-paste templates organised across five task types (提取ion, code, reasoning, writing, agentic tool use), tuned to V4-Pro and V4-Flash with the temperature and system-prompt patterns DeepSeek's own docs 推荐.

您打开了DeepSeek控制台,粘贴了“写一封营销邮件”,得到了一些通用的内容。问题不在于模型,而在于提示。经过六个月在DeepSeek V4-Pro和V4-Flash上通过生产工作负载——提取管道、代码审查、法律文件的RAG(阅读-询问-生成)、每周报告——运行后,我收集了一组DeepSeek提示模板库,这些模板始终优于临时请求。它们简短、结构化,并调整到DeepSeek文档实际推荐的参数。

本文为您提供了12个复制粘贴模板,按任务组织——提取、代码、推理、写作、代理工具使用——以及使它们工作的温度设置、系统提示结构和JSON模式注意事项。自2026年4月24日V4预览发布以来,每个模板都已针对`deepseek-v4-pro`和`deepseek-v4-flash`进行测试。

为什么在 DeepSeek V4 上提示模板更重要

Live 截图 of the DeepSeek prompt templates tool with categorized template list
Interactive tool

DeepSeek 提示模板库

23 tested-shape prompt skeletons that work reliably on V4. Search, filter by category, copy, fill the {placeholders}, send.

代码审查(文件级别)
Code
<role> Senior engineer 审查ing a pull request for production code. </role> <task> Review the file below and surface defects: bugs, race conditions, security issues, perf problems, unclear naming. </task> <file> {paste your file here} </file> <output_format> Numbered list. For each item: file:line — issue — 推荐ed fix. Skip nits. </output_format>
审查 pr 质量度
从堆栈跟踪复现的bug
Code
<role> Debugger. </role> <context> Language / framework: {language} Observed error: {paste stack trace} Relevant code: {paste suspect file or function} </context> <task> 1. Identify the root cause in one sentence. 2. Provide a minimal 复现 (5–10 lines). 3. Show the fix as a unified diff. </task>
调试 堆栈跟踪 复现
优化代码以提高可读性
Code
<task> Refactor the function below for 可读性 without changing behaviour. </task> <rules> - Keep public signatures identical. - Prefer early returns over deep nesting. - Add inline comments only where the WHY is non-obvious. - Output the 代码重构ed function only — no explanation. </rules> <code> {paste function} </code>
代码重构 可读性
测试生成(基于表格)
Code
<task> Write 基于表格 测试 for the function below. </task> <requirements> - Cover happy path, edge cases (empty, null, max, min, unicode), and 1–2 failure modes. - Use the project\'s existing test framework: {framework}. - Each case has: name, input, expected, expected_error. </requirements> <function> {paste function} </function>
测试 基于表格
生成一个清晰的提交信息
Code
<task> Write a 提交 message for the diff below. </task> <rules> - Subject line ≤ 50 chars, imperative mood. - Body lines wrap at 72 chars. - Explain the WHY, not the WHAT — the diff already shows the WHAT. - No trailers (no "Signed-off-by", no "Co-authored"). </rules> <diff> {paste diff} </diff>
提交 Git 变更日志
解释一个SQL查询
Code
<task> Explain what the SQL 查询 below does, in plain English, and identify any performance concerns. </task> <查询> {paste SQL} </查询> <output_format> 1. One-sentence 摘要. 2. Step-by-step walkthrough of the joins and filters. 3. Performance notes — full scans, missing indexes, cartesian risk. </output_format>
SQL 解释 db
文章大纲 → 草稿
Writing
<role> Writer for a software engineering audience. </role> <task> Expand the 大纲 below into a 草稿 文章. Conversational but technical. ~1200 words. </task> <大纲> {paste 大纲} </大纲> <voice> - No marketing language. - Concrete examples over abstract claims. - Short paRAGraphs. Subheads every 200–300 words. </voice>
大纲 草稿 文章
概括长文档(3层)
Writing
<task> Summarise the 文档 below. </task> <requirements> - Three layers: (1) one-sentence TL;DR, (2) 5-bullet executive 摘要, (3) section-by-section 摘要. - Preserve specific numbers and named entities. - Flag anything ambiguous as [unclear]. </requirements> <文档> {paste 文档} </文档>
摘要 TL;DR(太长不看) 文档
翻译(匹配语域)
Writing
<task> Translate the source below into {target_language}. </task> <rules> - Preserve register (technical, formal, casual — match what the source is). - Keep proper nouns and code untouched. - Where a phrase doesn\'t 翻译 清理ly, render it naturally and footnote with [literal: …]. </rules> <source> {paste source} </source>
翻译 本地化
撰写专业电子邮件回复
Writing
<task> Draft a 回复 to the 电子邮件 below. </task> <original> {paste 电子邮件} </original> <my_position> {what I want to convey} </my_position> <rules> - Match the 语调 of the original. - Address every direct question. - Keep ≤ 150 words. - No emojis, no exclamation marks unless the original used them. </rules>
电子邮件 回复 专业
修改而不改变意义
Writing
<task> Rewrite the text below to be clearer, more direct, and shorter — without changing any meaning, claim, or fact. </task> <rules> - Cut filler. Combine sentences only when clarity holds. - Active voice unless passive is required. - Don\'t paraphrase technical terms. - Output the 重写 only — no explanation. </rules> <text> {paste text} </text>
重写 语调 修改润色
步骤化问题解决
推理
<task> Solve the problem below. </task> <problem> {paste problem} </problem> <format> 1. Restate the problem in your own words. 2. List unknowns and givens. 3. Sketch an approach. 4. Work it through, step by step. 5. State the final answer plainly. 6. Sanity-check by plugging the answer back into the problem. </format>
cot(可能指某种技术术语或缩写,无法确定具体含义) 问题解决
决策树(选择一个)
推理
<task> Help me decide between options below. Don\'t restate; 推荐. </task> <options> - Option A: {描述} - Option B: {描述} - Option C: {描述} </options> <criteria_in_priority_order> 1. {first} 2. {second} 3. {third} </criteria_in_priority_order> <output_format> One paRAGraph: which option, then why in terms of the criteria. End with one risk and how to mitigate it. </output_format>
决策 选择 推荐
对一个想法进行钢人和红队分析
推理
<task> For the idea below, write the strongest possible case FOR it (steel-man), then the strongest case AGAINST it (红队分析). </task> <idea> {paste idea or proposal} </idea> <rules> - Each side gets ~5 distinct arguments. - Don\'t hedge. Make each argument as forcefully as a true believer would. - End with: which side I\'d believe more, and why. </rules>
批评 红队分析 钢人分析
从文本中进行结构化提取
数据
<task> Extract 结构化 information from the input. </task> <架构> { "people": [{"name": str, "role": str, "company": str | null}], "dates": [{"date": str (ISO), "event": str}], "amounts":[{"value": number, "unit": str, "context": str}] } </架构> <rules> - Output strict JSON only — no prose, no code fences. - Use null for missing fields. - ISO 8601 for dates. </rules> <input> {paste text} </input>
提取 json 结构化
带解释的分类
数据
<task> Classify each item below into one of: {label_a}, {label_b}, {label_c}, other. </task> <rules> - Output JSON: [{"id": str, "label": str, "置信度": float 0-1, "reason": str}]. - "reason" must be ≤ 15 words. - Use "other" rather than guessing. </rules> <items> {paste items} </items>
分类 标签 置信度
从英语生成SQL
数据
<task> Write a single SQL 查询 that answers the question. </task> <架构> {paste CREATE TABLE statements or DBML} </架构> <question> {your question} </question> <rules> - Use only the tables/columns in <架构>. - Comment any non-obvious join. - No explanation outside the 查询. </rules>
SQL nl2SQL 查询
清理和标准化混乱的CSV
数据
<task> Clean the CSV below: normalise dates to ISO 8601, trim whitespace, fix obvious typos, deduplicate rows by {key_column}, and flag suspicious values. </task> <rules> - Output the 清理ed CSV. - Append a separate ## Issues section listing every change you made and any rows you flagged. </rules> <CSV> {paste CSV} </CSV>
CSV 清理 转换
使用工具的智能体系统提示
代理
<role> A careful agent that uses tools when needed and reasons aloud before acting. </role> <tools_available> {list each tool name + one-line description} </tools_available> <process> 1. Read the user\'s goal carefully. 2. Think out loud (1–3 sentences) about what information you need. 3. Call a tool when you don\'t already know the answer. Never invent tool results. 4. After each tool result, decide: another tool, or final answer. 5. Give a clear, sourced final answer. </process> <rules> - One tool call per turn. - Cite tool results in the final answer ("according to the {tool_name} call …"). </rules>
工具调用 system 规划器
函数调用系统提示
代理
<role> You call functions when the user\'s request needs external 数据 or actions. </role> <rules> - Always prefer calling a function over guessing. - Match arguments exactly to the function 架构. - After receiving a tool_result, reason briefly, then either call another function or produce the final answer. - If no function fits, ask the user a clarifying question — don\'t hallucinate one. </rules>
函数调用 架构
描述一个用户界面截图
视觉
<task> Describe the UI in the attached image as if to someone who can\'t see it. </task> <format> 1. One-sentence overview (what kind of screen). 2. Layout: regions / panels / their relationship. 3. Notable controls and their state (enabled / disabled / selected). 4. Visible text content (preserve exactly). 5. Anything that looks broken or inconsistent. </format>
截图 ui 描述
从图表图像中提取数据
视觉
<task> Read the 图表 in the attached image and return its 数据 as a table. </task> <rules> - Output Markdown table with one row per 数据 point. - Note the 图表 type, axis 标签, and units. - For unlabelled values, estimate to within ±5% and flag as [estimated]. - If the 图表 is unreadable, say so plainly. </rules>
图表 提取 数据
带有引用的基于事实的回答
RAG(阅读-询问-生成)
<role> Answer questions only using the provided source 文档s. Cite by [doc_id]. </role> <rules> - If the answer isn\'t in the sources, say "I don\'t have that information in the provided sources." - Every factual claim ends with one or more [doc_id] 引用. - Don\'t mix in outside knowledge. </rules> <sources> {paste retrieved chunks, each prefixed with [doc_id]} </sources> <question> {user question} </question>
RAG 基于事实的 引用

每个模板都使用XML标签——DeepSeek V4可以可靠地解析这些标签。在发送前替换每一个。 {placeholder} 。

V4改变了规则。旧版模型名称 deepseek-chat and deepseek-reasoner 将于2026-07-24被弃用,并且它们现在对应于 deepseek-v4-flash 分别。这次迁移对模板很重要,因为思维不再是单独的模型——它是在两个模型中的请求参数。 deepseek-v4-pro or deepseek-v4-flash的非思考模式和思考模式。相同的提示根据是否设置了 reasoning_effort="high" with extra_body={"thinking": {"type": "enabled"}},或者关闭它,会产生可测量的不同输出。

V4的另一项变化是上下文。两个层级默认为1,000,000个令牌的窗口,输出最多384,000个令牌。这意味着模板可以更长,包含更多示例,嵌入更多参考资料,比V3.2上的更多。但如果你不结构化长提示,那么它们也会成为浪费。我们将在下面介绍缓存友好的布局。

关于底层模型的背景信息,请参阅 DeepSeek V4-Pro and DeepSeek V4-Flash如果您想深入了解提示理论而不是现成的模板,请参阅配套文章。 DeepSeek prompt engineering 是更好的起点。

四块模板结构

本文中的每个模板都遵循相同的四块布局。这是我找到的最容易维护的结构,也是上下文缓存指纹识别最容易的结构。

  1. 系统模块 ——角色、约束、输出格式。在调用之间保持稳定。
  2. 参考块 — 架构s, examples, retrieved 文档s. Mostly stable.
  3. 任务块 —— 本回合要做什么。每次调用可能发生变化。
  4. 用户输入 —— 易变内容(一个问题、一个文件、一行数据)。

块1和2属于 system 消息或第一条 user 消息的前面。块3和4放在后续 user 消息。因为默认温度是1.0,DeepSeek建议根据每个用例进行调整——代码和结构化分析接近0.0,一般对话约为1.3,创意工作高于1.0,以下每个模板都将提示与推荐的温度配对。

与每个模板搭配的温度设置

任务类型 Temperature Notes
代码生成、数学 0.0 确定性,更少的幻觉API
数据 提取ion, 清理ing 1.0 DeepSeek’s 推荐ed setting for analytical work
通用问答、翻译 1.3 默认的;平衡的
Creative writing, poetry 1.5 需要更多样性和更多修订

这些与DeepSeek官方在API参数文档页面上的指导一致。选择一个并坚持用于该模板——不要同时推送 top_p; DeepSeek和与OpenAI兼容的规范通常建议调整温度或top_p,但不要两者都调整。

模板 1 — 结构化提取(JSON 模式)

当你需要文本输出时使用此功能。DeepSeek API使用与OpenAI/Anthropic兼容的格式,因此你可以通过更改配置来使用OpenAI SDK针对DeepSeek基本URL。设置 response_format={"type": "json_object"}, set max_tokens 足够高以避免截断,并在提示中包含“json”一词以及一个小示例模式。

System:
You are a 结构化-数据 提取or. Return only valid JSON matching the 架构.
Do not include prose. If a field is unknown, return null.

Schema (example):
{
  "company": "Acme Inc",
  "amount_usd": 12500.00,
  "invoice_date": "2026-04-12",
  "line_items": [{"sku": "A-1", "qty": 2, "price": 19.99}]
}

User:
Extract a json record from the 电子邮件 below. Use the 架构 above.

[paste 电子邮件]

JSON模式旨在返回有效的JSON,但不保证。模型偶尔会返回空内容,因此请在解析时进行重试。完整警告已在文档中说明。 DeepSeek API JSON mode 指南。推荐模型: deepseek-v4-flash,非思考模式,温度1.0。

模板 2 — 带约束的代码生成

代码是温度-0设置发挥作用的地方。告诉模型语言、运行时、允许的库以及不想要的故障模式。

System:
You are a senior Python engineer. Write Python 3.12 code only.
所有owed libs: stdlib, httpx, pydantic. No requests, no global state.
Return one fenced code block plus a 3-line explanation.

User:
Write a function fetch_invoices(api_key: str, since: date) -> list[Invoice]
that pages /v1/invoices?since=... and returns a list of Pydantic Invoice
models with id, amount_cents, currency, paid_at fields.

For multi-file 代码重构s, switch to deepseek-v4-pro with thinking enabled. Pair this template with the workflow 描述d in DeepSeek for coding.

模板 3 — 思维模式下的推理

Flat-vector diagram of a cache-friendly DeepSeek V4 prompt template showing cached system and shot blocks plus fresh user input.

思考模式是一个参数,而不是一个模型。对于最困难的问题,设置 reasoning_effort="high" and extra_body={"thinking": {"type": "enabled"}}; the response returns reasoning_content alongside the final content. Use "max" —— 文档指出这需要 max_model_len >= 393216 to avoid truncation.

System:
You are a careful analyst. Think through the problem step by step in
reasoning_content. In content, return only the final answer in the
format requested.

User:
A SaaS charges $0.14 per 1M input tokens and $0.28 per 1M output.
We make 1M calls/day, each with 2,000 cached input + 200 fresh input
+ 300 output tokens. Cache-hit input is $0.0028/M. What is the daily
spend, broken down by bucket? Return a markdown table.

这就是本文前面提到的V4-Flash工作示例——每日总额为117.60美元(缓存5.60美元,缺失28美元,输出84美元)。展示数学计算胜过信任任何单一模型输出。

模板 4 — 缓存友好的系统提示

上下文缓存将V4-Flash的输入成本从每百万个标记0.14美元降低到0.0028美元,并将V4-Pro的列表价格从1.74美元/列表降至0.0145美元/列表,促销价格从0.435美元降至0.003625美元,直至2026年5月31日。当DeepSeek检测到重复的前缀时,缓存命中价格将自动应用。要触发它,请保持调用之间的前缀位相同。

  • Put the entire static instruction set, 架构s, and few-shot examples in 消息中 (系统)或消息的最前面 消息中 (用户)。
  • 请勿将时间戳、请求ID或每个用户的名称插入到前缀中。
  • 如果用户特定的位必须提前出现,请将其推入后续消息中,并保持系统块稳定。

关于缓存命中实际节省的数学计算,请参考 DeepSeek context caching 中的示例。

模板 5 — 引用来源的RAG(阅读-询问-生成)

System:
You answer questions only from the provided sources. Cite each claim
with the source id in square brackets, e.g. [S2]. If the sources do
not contain the answer, 回复: "Not in sources." Do not invent facts.

Sources:
[S1] {chunk 1 text}
[S2] {chunk 2 text}
[S3] {chunk 3 text}

User:
{question}

与检索功能配合使用,如 DeepSeek RAG(阅读-询问-生成) tutorial. Temperature 1.0; deepseek-v4-flash 中所述,对于大多数检索来说是可以的,当答案必须全面时,升级到V4-Pro。

模板 6 — 长文档摘要

在1M标记的上下文中,您很少需要分块只是为了适应。您仍然需要指导哪些内容需要总结。

System:
Summarise the 文档 in three layers:
1. One-sentence verdict
2. Five bullet key findings, each <= 20 words
3. Risks and unknowns, with section references like (p. 12)

Do not editorialise. Do not add information that is not in the 文档.

模板 7 — 基于角色的批判

角色提示之所以有效,是因为它们限制了词汇范围以及模型视为相关的内容。请具体说明。

You are a 数据base administrator with 15 years of Postgres experience.
Review the SQL below. List, in order of severity:
1. Correctness bugs
2. Performance issues at > 10M rows
3. Style problems
For each, quote the offending line and propose a fix.

模板 8 — 工具调用骨架

在OpenAI格式中,函数调用是可行的。声明工具,让模型发出工具调用,在客户端运行调用,并将结果附加到 messages,然后再次调用。API是无状态的——聊天请求击中 POST /chat/completions,OpenAI兼容的端点,并且你必须在每个回合重新发送对话历史。

from openai import OpenAI
client = OpenAI(base_url="https://api.deepseek.com", api_key="...")

tools = [{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "Current weather for a city",
    "parameters": {
      "type": "object",
      "properties": {"city": {"type": "string"}},
      "required": ["city"]
    }
  }
}]

resp = client.chat.completions.create(
    model="deepseek-v4-flash",
    messages=[{"role": "user", "content": "Weather in Dublin?"}],
    tools=tools,
)

完整模式请参见 DeepSeek API function calling.

模板 9 — 带有语域控制的翻译

Editor and terminal showing a DeepSeek 工具调用ing prompt template skeleton with tool_call and tool_result in flow.
Translate the text below from English to {target}.
Register: {formal|conversational|technical}.
Preserve: code blocks, URLs, numbers, proper nouns.
Output only the translation, no commentary.

温度设置为1.3产生的输出比0更自然;官方文档将1.3标记为推荐的翻译设置。

模板 10 — 创意写作大纲

Write a {format} of {length} words about {topic}.
Audience: {who}. Tone: {adjective + adjective}.
Constraints: {must include}. Avoid: {must not}.
Provide two distinct 草稿s, then a one-line note on the difference.

温度设置为1.5。如果两个草稿感觉相同,提高到1.7或重新运行——V4在低温下可能会锁定在单一声音上。

模板 11 — 测试用例生成器

For the function signature below, generate pytest 测试 covering:
- Happy path (3 cases)
- Edge cases (empty, single element, max size)
- Error cases (invalid type, out-of-range)
Return one fenced code block. No commentary.

{paste signature + docstring}

模板 12 — 自我批判环节

Cheap on V4-Flash, often worth running. The first call 草稿s; the second 批评s and 重写s.

Pass 1 (temperature 1.3): Draft the response.
Pass 2 (temperature 0.0): "Critique the 草稿 below for factual errors,
weak claims, and structural problems. Rewrite to fix them. Output only
the rewritten version."

端点和参数参考

上述每个模板都发送到 POST /chat/completions at https://api.deepseek.comDeepSeek的API与OpenAI和Anthropic兼容,因此您可以在任一SDK中交换基本URL和密钥。上述模板中出现的参数:

  • model — deepseek-v4-pro or deepseek-v4-flash
  • temperature —参见上表
  • max_tokens —使用JSON模式时,将其设置为高(例如8000+)
  • reasoning_effort — "high" or "max" with extra_body={"thinking": {"type": "enabled"}}
  • response_format — {"type": "json_object"} —针对模板1
  • tools —针对模板8
  • stream —对于聊天用户界面为真

—关于设置,请参阅 how to get a DeepSeek API key—有关包括提示生成器在内的更广泛工具集,请参阅 DeepSeek tools and utilities hub.

我不会做什么

Diagram of a DeepSeek prompt template library mapping categories into a 结构化 prompt sent to the DeepSeek API.
  • —系统提示中的行内时间戳——杀死缓存命中。
  • —设置两者 temperature and top_p aggressively — 选择 one.
  • 使用思考模式回答简短的事实性问题——您将支付不需要的输出令牌费用。
  • 信任JSON模式而不使用解析器回退——它是“设计用来”返回JSON的,但不保证。
  • 引用第三方博客中的单个SWE-Bench数字,但不要检查分割情况(验证版 vs 完整版 vs 轻量版)。

DeepSeek AI Guide is an independent resource and is not affiliated with DeepSeek or its parent company. Model IDs, pricing and API behaviour change; check the official DeepSeek 文档ation and pricing page before 提交ting to a production 决策.

Frequently asked questions

<摘要>

我该如何为DeepSeek V4编写系统提示?

将角色、约束和输出格式放入 system 消息并保持其在调用间位相同,以便上下文缓存可以命中。在同一块中添加模式或少量示例。将易变内容(时间戳、用户名、今天的问题)保存以供后续使用。 user 消息。我们使用的是四块结构的消息。 DeepSeek prompt engineering 指南适用于V4-Pro和V4-Flash。

<摘要>

我应该使用什么温度与DeepSeek提示模板一起使用?

DeepSeek的文档建议代码和数学为0.0,数据分析为1.0,一般对话和翻译为1.3,创意写作为1.5。默认值为1.0。将温度与您正在运行的模板相匹配——代码模板为0.0,创意模板为1.5。更多指导信息请参阅。 DeepSeek API best practices reference.

<摘要>

我可以使用相同的提示为V4-Pro和V4-Flash使用吗?

是的——两个级别共享相同的API界面和提示格式。区别在于成本和能力上限:V4-Pro在输出上大约是V4的六到七倍,对于前沿编码或代理工作来说物有所值。对于聊天、提取和大多数RAG(阅读-询问-生成),V4-Flash是默认选项。在上比较两者。 DeepSeek pricing calculator.

<摘要>

DeepSeek JSON模式是否能保证有效的JSON输出?

不。DeepSeek的文档描述JSON模式是为了返回有效的JSON,但不保证。模型偶尔可能会返回空内容,因此始终在try/except中包装解析并重试。在提示中包含“json”一词以及一个示例模式,并设置 max_tokens 足够高,以至于响应不会在对象中间被截断。 DeepSeek API JSON mode 文档详细介绍了故障情况。

<摘要>

为什么我的DeepSeek提示模板比预期更贵?

几乎总是以下三种情况之一:系统提示在调用之间发生变化(无缓存命中)。 max_tokens 限制未开启,因此思考模式会产生大量痕迹,或者您正在使用 V4-Pro 而不是 V4-Flash。请检查令牌计数。 DeepSeek token counter and 审查 the cost breakdown by bucket — cached input, uncached input, and output — separately.

Sources & Methodology

Last source check: April 30, 2026

Primary sources

Technical references

Methodology

Information in this 文章 was checked against the official DeepSeek 文档ation, the 文章's cited primary sources, and the deepseekai.guide pricing 数据set on the date shown above. Where third-party numbers are quoted, the originating source is linked inline so the reader can verify and re-check.

数据 置信度

High for facts cited inline with primary-source links; medium for context narrative.

Editorial note

AI tooling moves quickly. If you spot an outdated number or a broken link, the contact link in the footer is the fastest way to flag it for the editorial team.