0Pricing
AI Prompt Engineering · 课时

为什么具体性很重要

了解模糊提示如何导致泛泛的输出,以及精确表达如何解决这一问题

为什么具体性很重要 是 CoddyKit 上的免费 AI Prompt Engineering 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Prompt Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Prompt Engineering 课程共包含 4 节课。

模糊性问题

当您发送模糊的提示时,人工智能会用它的最佳猜测填补所有缺失的细节。这些猜测基于统计上最常见的解释,而不是您的真实意图。

结果是通用且令人难忘的输出,需要大量重写。具体性是您改善人工智能输出质量的最有力手段。

模糊提示:写关于狗的内容

请考虑这个提示:“写点关于狗的内容。”

模型必须猜测:采用什么格式?多长?面向什么读者?从什么角度切入?它通常会默认生成一段安全而平淡的文字,放进儿童百科全书也不会突兀。

现在比较一下:“为一只金毛寻回犬幼犬在海滩度过的第一天撰写一段 200 字的图片社交平台配文。语气:活泼且富有情感。加入 5 个相关主题标签。”

第二个提示没有留下任何需要猜测的地方。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

vague = 'Write something about dogs.'
specific = (
    'Write a 200-word Instagram caption for a golden retriever puppy\'s '
    'first day at the beach. Tone: playful and emotional. '
    'End with 5 relevant hashtags.'
)

for label, prompt in [('VAGUE', vague), ('SPECIFIC', specific)]:
    response = client.messages.create(
        model='claude-opus-4-5',
        max_tokens=300,
        messages=[{'role': 'user', 'content': prompt}]
    )
    print(f'--- {label} ---')
    print(response.content[0].text)
    print()

为什么会产生通用输出

模型是在数十亿个文本示例上训练的。当您说“写关于 X 的内容”时,它会生成训练期间见过的关于 X 的最常见文本类型。

这种文本通常具有以下特点:

  • 百科全书式的语气
  • 中等篇幅
  • 表面涵盖所有主要角度
  • 没有鲜明的风格或目的

您的具体约束会覆盖这些默认设置,引导模型满足您的实际需求。

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

# Default (vague) output
default_response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{'role': 'user', 'content': 'Write about coffee.'}]
)
print('DEFAULT OUTPUT (first 200 chars):')
print(default_response.choices[0].message.content[:200])
print()

# Constrained output
constrained_response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{
        'role': 'user',
        'content': (
            'Write a 100-word product description for a single-origin Ethiopian pour-over coffee. '
            'Target audience: specialty coffee enthusiasts. '
            'Tone: sophisticated, sensory. Mention flavor notes: jasmine, blueberry, dark chocolate.'
        )
    }]
)
print('CONSTRAINED OUTPUT:')
print(constrained_response.choices[0].message.content)

具体性的五个维度

编写提示时,请从以下五个维度进行具体说明:

  1. 格式——段落、项目符号列表、表格、JavaScript 对象表示法、电子邮件
  2. 长度——字数、句子数、项目数
  3. 受众——谁会阅读或使用这份输出
  4. 语气——正式、随意、技术性、具有说服力、富有同理心
  5. 目标——输出应该实现什么目的

您不一定总需要全部五项,但缺少其中任何一项,都可能让模型猜错。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

# All 5 dimensions specified
response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=256,
    messages=[{
        'role': 'user',
        'content': (
            'Format: 3-bullet summary.\n'
            'Length: each bullet max 20 words.\n'
            'Audience: busy startup founders with no ML background.\n'
            'Tone: direct, no jargon.\n'
            'Goal: explain why fine-tuning an LLM is expensive.'
        )
    }]
)
print(response.content[0].text)

模糊与具体:电子邮件请求

让我们看看电子邮件写作,这是最常见的人工智能任务之一。

模糊:“给我的客户写一封电子邮件。”
模型不知道客户是谁、主题是什么、双方是什么关系、目标是什么,也不知道应采用什么语气。

具体:“给一位逾期付款 14 天的 B2B SaaS 客户(TechFlow 公司)写一封三段式电子邮件。语气:坚定但保持专业礼貌。目标:促使对方付款,同时不损害双方关系。加入明确的行动号召,并设定 5 天期限。”

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

specific_prompt = (
    'Write a 3-paragraph professional email to a B2B SaaS client (TechFlow Inc) '
    'who has a payment 14 days overdue. '
    'Tone: firm but courteous — preserve the business relationship. '
    'Include: acknowledgment of potential oversight, the overdue amount placeholder [AMOUNT], '
    'a payment link placeholder [LINK], and a 5-day deadline. '
    'Subject line included.'
)

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{'role': 'user', 'content': specific_prompt}]
)
print(response.choices[0].message.content)

模糊与具体:摘要

即使是看似简单的摘要任务,也能从明确具体的要求中获益匪浅。

模糊:“总结这篇文章。”

具体:“请用恰好 3 个句子总结这篇文章。第一句:主要发现。第二句:所使用的方法。第三句:对实践者最重要的影响。”

结构明确的版本可以立即使用;模糊版本则需要重新调整格式。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

article = (
    'Researchers at MIT have developed a new neural network architecture that achieves '
    '94% accuracy on medical image diagnosis, outperforming human radiologists by 7%. '
    'The model was trained on 2.4 million anonymized X-ray images and uses a novel '
    'attention mechanism that highlights regions of interest for clinician review. '
    'The team expects FDA clearance by Q3 2025 for use as a diagnostic aid, not replacement.'
)

specific_prompt = (
    f'Summarize the following article in exactly 3 sentences:\n'
    f'Sentence 1: main finding.\n'
    f'Sentence 2: methodology.\n'
    f'Sentence 3: key implication for clinicians.\n\n'
    f'Article:\n{article}'
)

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=200,
    messages=[{'role': 'user', 'content': specific_prompt}]
)
print(response.content[0].text)

模糊与具体:头脑风暴

头脑风暴提示词最不能含糊,因为您会得到一串显而易见且彼此重复的想法。

模糊:“为我的应用提供一些想法。”

具体:“请为一款面向 25 至 35 岁城市职场人士的 B2C 冥想应用提供 10 种独特的变现策略。排除订阅模式(我们已经有一种)。每个想法用一个句子表达,并按风险从高到低排序。”

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

specific_brainstorm = (
    'Generate 10 unique monetization strategies for a B2C meditation app '
    'targeting 25-35 year-old urban professionals. '
    'Exclude: subscription models (already implemented). '
    'Each strategy in one sentence. '
    'Order from most to least conventional. '
    'Label each with: CONVENTIONAL / EXPERIMENTAL / BOLD.'
)

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[{'role': 'user', 'content': specific_brainstorm}]
)
print(response.choices[0].message.content)

在提示词中使用示例

最强大的具体化技巧之一,就是直接在提示词中加入您希望得到的输出示例(这称为少样本提示)。

不要只是描述格式,而要把格式展示出来。模型能从真实示例中立即理解结构、长度和语气,通常比从文字描述中理解得更清楚。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

example_prompt = '''
Generate 3 product taglines in this style:

Example 1: Notion — 'The all-in-one workspace where better thinking happens.'
Example 2: Figma — 'Design together. Ship faster.'
Example 3: Linear — 'The issue tracker you'll actually enjoy using.'

Product: A CLI tool that automatically writes Git commit messages by analyzing your diff.
Taglines:
'''

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=200,
    messages=[{'role': 'user', 'content': example_prompt}]
)
print(response.content[0].text)

明确 NOT 应避免的事项

负向约束和正向约束同样强大。告诉模型要避免什么,有助于防止常见的不良模式:

  • “不要使用项目符号”
  • “不要以‘我’这个词开头”
  • “不要建议需要信用卡的解决方案”
  • “不要使用被动语态”

将正向指令与负向约束结合起来,可以实现最大程度的控制。

import openai

client = openai.OpenAI(api_key='sk-your-key-here')

response = client.chat.completions.create(
    model='gpt-4o',
    messages=[
        {
            'role': 'system',
            'content': (
                'You are a copywriter. Rules:\n'
                '- NEVER start a sentence with "Additionally" or "Furthermore"\n'
                '- NEVER use the phrase "In conclusion"\n'
                '- NEVER use passive voice\n'
                '- NEVER use bullet points or lists'
            )
        },
        {
            'role': 'user',
            'content': 'Write a 100-word about us section for a craft bakery called Morning Light.'
        }
    ]
)
print(response.choices[0].message.content)

迭代式具体化

您不必第一次尝试就写出完美的提示词。迭代完善是一种有效策略:

  1. 从一个具体程度适中的提示词开始
  2. 找出输出中错误或缺失的内容
  3. 添加约束来解决这些问题
  4. 重复上述过程,直到输出达到您的标准

每次迭代都会帮助您了解模型需要哪些约束。请将最好的提示词保存为模板,以便日后使用。

import anthropic

client = anthropic.Anthropic(api_key='sk-ant-your-key-here')

# Iteration 1: first attempt
v1 = 'Write a LinkedIn post about my new job.'

# Iteration 2: add specifics based on what was missing
v2 = (
    'Write a LinkedIn post (max 150 words) announcing I just joined Stripe as a Senior Engineer. '
    'Tone: genuine excitement, not bragging. '
    'Include: what drew me to the role, one thing I plan to focus on. '
    'No cliches like "excited to announce" or "humbled to share". '
    'End with a genuine question for my network.'
)

response = client.messages.create(
    model='claude-opus-4-5',
    max_tokens=300,
    messages=[{'role': 'user', 'content': v2}]
)
print(response.content[0].text)

建立具体性检查清单

发送任何提示词之前,请在心中过一遍这份检查清单:

  • 我是否指定了输出格式?(段落 / 列表 / JSON / 表格)
  • 我是否指定了长度?(字数 / 项目数量)
  • 我是否指定了受众?(谁会阅读这些内容)
  • 我是否指定了语气?(正式 / 随意 / 技术性)
  • 我是否指定了目标?(这些输出将用于什么目的)
  • 我是否加入了约束?(需要避免什么)
  • 我是否可以添加一个示例来说明我的意思?
# Prompt template with all specificity dimensions filled
prompt_template = '''
Task: {task_description}
Format: {format}
Length: {length}
Audience: {audience}
Tone: {tone}
Goal: {goal}
Do NOT: {constraints}
Example of good output: {example}
'''

filled = prompt_template.format(
    task_description='Explain what an API is',
    format='3 short paragraphs, plain prose — no bullet points',
    length='150 words maximum',
    audience='Non-technical business stakeholders',
    tone='Friendly, analogy-based, jargon-free',
    goal='Prepare them for a meeting with the engineering team',
    constraints='Do not use the words "endpoint", "REST", or "HTTP"',
    example='An API is like a waiter in a restaurant — it takes your order...'
)
print(filled)

知识检查

一位市场营销经理向人工智能提出请求:“写一篇社交媒体帖子。”人工智能返回了一篇泛泛的、介绍公司的两句式帖子。哪种 BEST 改写方式最能得到有用的结果?

具体性为何重要——回顾

具体性是有效编写提示词的基础。关键要点:

  • 模糊的提示词会产生统计意义上平均、泛泛的输出
  • 每个提示词都应明确格式、长度、受众、语气和目标
  • 使用负向约束来防止不希望出现的模式
  • 加入您希望的输出风格示例
  • 采用迭代完善的方法——没有哪个提示词必须第一次尝试就完美
  • 将成功的提示词保存为可重复使用的模板

您描述得越具体,花在重写输出上的时间就越少。

常见问题解答

「为什么具体性很重要」课时是免费的吗?

是的 — 「为什么具体性很重要」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Prompt Engineering 课程的其余内容,请升级到 CoddyKit PRO。 AI Prompt Engineering 课程共包含 4 节课。

「为什么具体性很重要」这节课中我会学到什么?

了解模糊提示如何导致泛泛的输出,以及精确表达如何解决这一问题 你通过在浏览器中直接运行的动手代码来练习 AI Prompt Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 AI Prompt Engineering 需要有经验吗?

无需任何先前经验。CoddyKit 上的 AI Prompt Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。

「为什么具体性很重要」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 AI Prompt Engineering 课中编写并运行代码吗?

能。每节 AI Prompt Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 为什么具体性很重要
  2. 消除提示中的歧义
  3. 添加具体细节
  4. 比较模糊提示与具体提示
← 返回 AI Prompt Engineering