添加具体细节
用数字、名称、格式和示例为人工智能输出提供明确依据。
添加具体细节 是 CoddyKit 上的免费 AI Prompt Engineering 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Prompt Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Prompt Engineering 课程共包含 4 节课。
具体细节是锚点
具体细节是明确、可衡量且可验证的信息。它们会将模型的输出锚定在您的实际情况上,而不是泛泛的理解上。
没有锚点时,模型会为想象中的普通用户生成内容;有了锚点后,它生成的内容才是为您量身定制的。
用字数作为具体约束
字数是您可以添加的最简单、最有效的具体细节之一。请比较:
- 模糊:“写一段简短的描述”
- 具体:“写一段 75 字的描述”
模型会统计词元,并尽量达到您的目标。如果字数略有偏差,您可以要求它重新精确统计。指定字数可以消除大量重写需求。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=200,
messages=[{
'role': 'user',
'content': (
'Write a product description for a noise-cancelling travel pillow in exactly 60 words. '
'After the description, output the word count in parentheses on a new line.'
)
}]
)
print(response.content[0].text)将目标受众作为具体细节
明确指定具体的受众,会显著改变输出所使用的词汇、示例和深度。
- 模糊:“解释神经网络”
- 具体:“向一家《财富》世界500强企业的市场营销经理解释神经网络;对方没有编程背景,但理解电子表格数据透视表”
第二个提示词让模型能够想象真实读者的情况,从而准确调整复杂程度。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
concrete_audience_prompt = (
'Explain what a REST API is.\n\n'
'Audience: a non-technical product manager who uses Salesforce daily '
'and understands the concept of a form submission on a website. '
'They will use this explanation to brief their engineering team tomorrow. '
'Use one real-world analogy. Max 100 words.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': concrete_audience_prompt}]
)
print(response.choices[0].message.content)使用命名实体,而非泛化描述
使用命名实体——真实的产品名称、公司名称、人物、技术和日期——可以迫使模型摆脱泛泛而谈的范围。
- 模糊:“写一份竞争分析”
- 具体:“为一位管理着 10 人远程团队、每天写作且需要离线访问的高级用户,撰写一份关于笔记工具甲、笔记工具乙和笔记工具丙的竞争分析”
命名实体会将模型锚定到它在训练中获得的真实世界知识上。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=400,
messages=[{
'role': 'user',
'content': (
'Compare FastAPI vs Flask vs Django REST Framework '
'for building a production API that will serve a React frontend. '
'Context: 2-person startup team, Python 3.11, needs async support, '
'expects < 50 ms response time, and will deploy on AWS Lambda. '
'Format: 3-column markdown table with rows: setup complexity, '
'async support, performance, learning curve, community size.'
)
}]
)
print(response.content[0].text)量化约束
数字不会产生歧义。只要有数值要求,就应将其写入提示词:
- 列出恰好 N 个项目(不要写“几个”或“若干”)
- 设置字数或字符数的最大值 / 最小值
- 指定具体百分比或比例(“70% 实践,30% 理论”)
- 设置时间约束(“请按照我只有 3 分钟阅读时间来解释”)
- 设定性能目标(“建议能够实现 O(n) 时间复杂度的方法”)
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
'Generate exactly 8 onboarding email subject lines for a B2B SaaS product. '
'Requirements:\n'
'- Exactly 8 lines, no more, no fewer\n'
'- Each subject line between 40 and 60 characters\n'
'- 4 must emphasize value, 4 must create urgency\n'
'- Label each line: [VALUE] or [URGENCY]\n'
'- No emojis\n'
'- No duplicate words across all 8 lines'
)
}]
)
print(response.choices[0].message.content)截止时间与基于时间的设定
提供时间背景会改变输出的深度和重点。请告诉模型这些内容何时会被使用,以及由此产生的约束:
- “这封电子邮件将在 2 小时后发送——请保持简洁”
- “这是周一董事会演示要用的内容——使用面向高管的语言”
- “这段解释需要适合 5 分钟的站立会议”
- “请为一个在客户通话前只有 10 分钟审核时间的团队撰写这段内容”
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=256,
messages=[{
'role': 'user',
'content': (
'Write a project status update for our AI chatbot project. '
'This will be read aloud at a 5-minute Monday morning stand-up. '
'The audience has zero technical background. '
'Talking time: max 2 minutes (approximately 300 words). '
'Cover: what we shipped last week, one current blocker, one upcoming milestone. '
'Tone: confident and factual. No jargon.'
)
}]
)
print(response.content[0].text)提示词中的具体示例
在提示词中加入您想要的内容或您不想要的内容的具体示例,是效果最显著的技巧之一。示例可以同时教会模型输出格式、口吻和风格。
您可以包含:
- 理想输出的示例(单示例)
- 带标签的多个示例(少样本)
- 之前出错的示例(反面示例)
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
prompt = '''
Write 3 feature announcement tweets for a new developer tool.
Here is an example of the style I want:
"We just shipped inline type errors in the editor. No more tab-switching to find
what broke. Your flow stays unbroken. Try it now: [link]"
Characteristics of this style:
- Opens with what shipped, not with excitement words
- Describes the user benefit in the second sentence
- Ends with a CTA
- No hashtags. No emojis. Under 200 characters.
New feature: autocomplete that learns from your codebase.
'''
response = client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': prompt}]
)
print(response.choices[0].message.content)特定领域词汇
在提示词中加入特定领域的术语,可以向模型表明输出应达到的专业水平。
- “解释缓存” → generic 响应
- “为一名正将后端系统从 Memcached 迁移到 Redis 7.x 的后端工程师,解释 Redis LRU 淘汰策略” → 专家级、立足具体领域的响应
在提示词中使用您所在领域的词汇,模型也会在输出中采用这些词汇。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
# Generic prompt vs domain-vocabulary prompt
generic = 'Explain caching strategies.'
domain_anchored = (
'Compare write-through, write-behind, and cache-aside patterns '
'for a microservices architecture using Redis 7.x as the cache layer and '
'PostgreSQL 15 as the source of truth. '
'Focus on consistency guarantees, latency tradeoffs, and failure modes. '
'Audience: senior backend engineers familiar with CAP theorem.'
)
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=400,
messages=[{'role': 'user', 'content': domain_anchored}]
)
print(response.content[0].text)要排除内容的约束
明确的否定约束(排除项)可以防止模型走向那些可预料的、generic 的方向:
- “不要建议需要付费应用程序接口密钥的解决方案”
- “不要提及竞争对手的名称”
- “不要使用‘杠杆’或‘协同效应’这两个词”
- “不要包含理论内容——只提供实用内容”
- “排除需要超过 5 分钟才能实施的方法”
每条排除规则都会再排除一种泛泛内容的可能,从而使输出更加精准。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
'Suggest 5 ways to speed up a slow Python script. '
'EXCLUDE:\n'
'- Suggestions requiring third-party libraries (stdlib only)\n'
'- Suggestions about hardware upgrades\n'
'- Rewrites of the entire script\n'
'- Suggestions that take more than 30 minutes to implement\n'
'Each suggestion: one sentence describing what to do, one sentence on expected speedup.'
)
}]
)
print(response.choices[0].message.content)整合所有要素
让我们逐步构建一个完全具体的提示词。先从:“撰写一份职位描述。”开始。
- 添加职位:“面向一名高级机器学习工程师”
- 添加指定实体:“就职于伦敦一家 B 轮人工智能初创公司”
- 添加字数:“350—400 字”
- 添加受众:“面向拥有 5 年以上经验的候选人”
- 添加结构:“格式:简介、职责(8 个项目)、任职要求(5 个项目)、加分项(3 个项目)”
- 添加排除项:“不要使用‘快节奏’或‘充满激情’之类的陈词滥调”
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
concrete_prompt = (
'Write a job description for a Senior ML Engineer position '
'at a Series B AI startup in London. '
'Target candidate: 5+ years ML experience, strong Python, familiar with LLMs. '
'Length: 350-400 words. '
'Structure:\n'
'1. 3-sentence company intro (no fluff — focus on product and mission)\n'
'2. Responsibilities: exactly 8 bullet points\n'
'3. Requirements: exactly 5 bullet points\n'
'4. Nice-to-haves: exactly 3 bullet points\n'
'EXCLUDE: phrases like "fast-paced", "passionate", "ninja", "rockstar", "self-starter".'
)
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=600,
messages=[{'role': 'user', 'content': concrete_prompt}]
)
print(response.content[0].text)完善提示词的习惯
养成在发送每条提示词前先进行完善的习惯。快速进行以下思考:
- 我能否用一个数字替换某个模糊的词?
- 我能否指定一个具体的工具、技术或人物?
- 我能否更准确地说明受众?
- 我能否加入一个说明理想内容的示例?
- 我能否至少加入一条“不要包含”的约束?
- 我能否更准确地指定输出格式?
即使只补充两三项细节,也能显著提升输出质量。
# Prompt enrichment in code form: before/after comparison
before = 'Give me ideas for my presentation.'
after = (
'Generate 6 opening hook ideas for a 15-minute conference talk '
'titled "Why Your AI Prompts Are Failing You" at PyCon 2025. '
'Audience: Python developers, mostly backend, some ML experience. '
'Each hook: 2 sentences max. '
'Mix: 2 provocative statistics, 2 counterintuitive questions, 2 short stories. '
'EXCLUDE: "Did you know..." openers and rhetorical questions about the future of AI.'
)
print('BEFORE:', before)
print()
print('AFTER:', after)知识检查
一位初创公司创始人发送了这条提示词:“请帮我撰写营销文案。”下面哪个修改后的提示词使用了最有效的具体细节?
添加具体细节——回顾
具体细节可以把模糊的提示词转化为精确的指令。请使用以下锚定技巧:
- 字数:用准确的数字替换“短/长”
- 命名实体:具体的产品、工具、公司和人物
- 受众:职位、经验水平以及他们已经了解的内容
- 量化约束:恰好包含 N 个项目,每种类型占 N%
- 领域词汇:使用该领域自身的术语,以表明预期的深度
- 示例:展示优质输出应是什么样子
- 排除项:明确模型应避免的内容
用 AI 导师学习 AI Prompt Engineering — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 53
- 课程
- 199
常见问题解答
「添加具体细节」课时是免费的吗?
是的 — 「添加具体细节」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Prompt Engineering 课程的其余内容,请升级到 CoddyKit PRO。 AI Prompt Engineering 课程共包含 4 节课。
「添加具体细节」这节课中我会学到什么?
用数字、名称、格式和示例为人工智能输出提供明确依据。 你通过在浏览器中直接运行的动手代码来练习 AI Prompt Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 AI Prompt Engineering 需要有经验吗?
无需任何先前经验。CoddyKit 上的 AI Prompt Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「添加具体细节」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 AI Prompt Engineering 课中编写并运行代码吗?
能。每节 AI Prompt Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。