介绍经过实战验证的AI提示词用法,通过强制表述假设+反向提问的方式,将复杂bug排查时间从数小时压缩到十分钟,适用于任何语言和框架。
大多数讲 AI 提示词的文章要么是泛泛的废话,要么展示的东西你在真实项目中永远用不上。这篇不一样。过去一年,我一直在真实客户、真实 deadline 和混乱的代码库里测试提示词。下面是经过筛选的五个——每一个都能把某个特定的、重复性的任务从几小时压缩到几分钟。不玩虚的,直接复制粘贴,稍作调整就能用。
你肯定有过这种感觉:盯着一个堆栈跟踪看了几个小时,坚信这个 bug 是某种宇宙级bug。别这样。在你动任何东西之前,先用这个提示词:
You are a senior developer with 20 years of experience. I will paste a code snippet, an error message, and my current hypothesis. Do not give me a solution yet. Instead, ask me three questions that would help YOU narrow down the root cause. Then wait for my answers. After I respond, give me the most likely fix and the second most likely fix, ranked by probability. If my hypothesis is wrong, explain why in one sentence.
为什么有效:它强迫你把自己的假设说出来,而 AI 的问题往往会揭示你忽略的那个显而易见的东西。原本要花两小时,结果十分钟搞定。任何语言、任何框架都能用。
重构别人写的 spaghetti 代码是件可怕的事。这个提示词把 AI 变成一个谨慎的搭档,而不是一个蛮干的牛仔:
Here is a function (paste it). I need to refactor it to [achieve X]. Constraints: do not change the public API, do not alter the behavior for edge cases, and preserve all existing comments. First, list every behavior the current code exhibits that a test might catch. Then, propose a refactor in 3 steps. For each step, show the diff and explain why it's safe. End with a list of new test cases I should add to verify the refactor.
你会得到一个尊重现有测试的重构计划,外加一份测试清单。再也不会出现"我直接重写,然后祈祷没事"的局面。
从零开始写 OpenAPI 规范或 Postman 集合是件让人麻木的事。把实际的请求/响应 JSON 喂给 AI:
I have a REST endpoint. Here is the request body (paste JSON), the response body (paste JSON), and the list of possible status codes with their example responses. Generate a complete OpenAPI 3.0 YAML spec for this endpoint. Include proper schemas, descriptions, and error examples. Do not add extra endpoints. Use `operationId` names that match the endpoint's purpose. If you see a security header in my request, add a security scheme for it.
把输出粘贴到你的规范文件里,调整一下 info 块,搞定。每个端点至少省下一小时,而且很准确——因为基于的是真实数据。
你不需要再装一个笔记应用。你需要的是一个能把原始 transcript 转成决策的提示词:
Here is a transcript of a client meeting (paste the text). I am the developer. Extract: 1) Every decision that was made, with the person who made it. 2) Every open question that I still need to answer, worded as a direct question to me. 3) A list of deliverables with a suggested priority (P0/P1/P2) based on how the client spoke. 4) Any numbers, deadlines, or budget figures mentioned. Format as a table for decisions, and a separate list for questions. Do not summarize the conversation.
这样在会议结束前你就得到了一份可执行的清单。再也不会忘记客户随口说的"周五之前部署"了。
在推送那个 PR 之前,先跑一下这个,捕捉愚蠢的错误和逻辑漏洞:
Act as a junior developer who writes clean code but lacks deep context. I will paste my code. Review it with these lenses: 1) Are there any variables that are declared but never used? 2) Are there any potential null/undefined access paths? 3) Is there a loop that might run longer than expected? 4) Are there any hardcoded values that should be configurable? Output a numbered list of issues, each with a line number and a one-sentence fix suggestion. Do not comment on style or naming—only functional problems.
你会惊讶于这个提示词能捕捉到多少真实的 bug。它不能替代资深工程师的 review,但确实是一张非常好的安全网。
客户要你用一个你从来没见过的框架。不要去看四十分钟的教程。这样做:
I need to learn [framework/library] enough to build [specific feature] by tomorrow. I already know [list similar tech you know]. Give me a 15-minute learning path: first, the core concept in one paragraph with a tiny code example. Then, the three most common mistakes beginners make. Then, a minimal working example for [my feature]. Finally, a list of the official docs pages I should bookmark. Do not give me a full tutorial—just the fastest route to my goal.
十五分钟后,你已经在写真正的代码了。搞定。
有一点要注意:这些提示词如果不粘贴真实的上下文,都不会生效。AI 的质量取决于你喂给它的"垃圾"。在回车之前花三十秒编辑一下你的代码片段,这样你省下的就不是三十分钟,而是三小时。
还有一件事——你可能一直在浪费时间满世界找这些模板,或者凭记忆重新构建。我把上面这些全部打包成了一个带占位符的简洁 Markdown 文件,还额外加了十几个用于计费、客户沟通和数据库查询的提示词。如果你厌倦了重复输入提示词,这是一个便宜的下载。
我在一个小型自动化的 Telegram 商店里卖这类数字包——即时 USDT 交付。可以来看看:https://t.me/m3lmhermes_bot