Part04:提示词示例

提示词实战:从基础到进阶的七大应用场景

上一节我们介绍了提示词的基本概念,本节将通过七个具体的应用场景,展示如何通过精心设计的提示词来执行不同类型的任务。学习概念的最佳方式往往是通过实例,以下示例将带你深入了解提示工程的实际应用。

文本概括

文本摘要是自然语言生成的标准任务之一。语言模型最有前景的应用之一,就是将复杂的文章和概念概括成简洁易读的摘要。

基础摘要任务

我们可以尝试使用提示词进行一个基本的摘要任务。注意这里使用了"A:"作为显式提示格式,告诉模型接下来期望有一个答案。

提示词:

Explain antibiotics

A:

输出:

Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.

进阶控制:一句话总结

如果你觉得模型提供的信息过多,可以指导模型用一句话总结相关内容,从而进一步提炼信息。

提示词:

Antibiotics are a type of medication used to treat bacterial infections. They work by either killing the bacteria or preventing them from reproducing, allowing the body's immune system to fight off the infection. Antibiotics are usually taken orally in the form of pills, capsules, or liquid solutions, or sometimes administered intravenously. They are not effective against viral infections, and using them inappropriately can lead to antibiotic resistance.

Explain the above in one sentence:

输出:

Antibiotics are medications used to treat bacterial infections by either killing the bacteria or stopping them from reproducing, but they are not effective against viruses and overuse can lead to antibiotic resistance.

信息提取

虽然语言模型主要用于自然语言生成,但它们在分类和信息提取等自然语言处理任务上同样表现出色。

示例:提取特定产品名

这是一个从给定段落中提取特定信息的提示词示例。

提示词:

Author-contribution statements and acknowledgements in research papers should state clearly and specifically whether, and to what extent, the authors used AI technologies such as ChatGPT in the preparation of their manuscript and analysis. They should also indicate which LLMs were used. This will alert editors and reviewers to scrutinize manuscripts more carefully for potential biases, inaccuracies and improper source crediting. Likewise, scientific journals should be transparent about their use of LLMs, for example when selecting submitted manuscripts.

Mention the large language model based product mentioned in the paragraph above:

输出:

The large language model based product mentioned in the paragraph above is ChatGPT.

你可以通过多种方法改进上述结果,但这已经展示了通过简单指示让模型执行不同任务的强大能力。

问答

让模型给出具体回答的最佳方法之一是改善提示词的格式。结合指令、上下文、输入和输出指示,通常能获得更好的结果。

结构化提示词示例

以下示例展示了更结构化的提示词格式,包含明确的上下文和约束条件。

提示词:

Answer the question based on the context below. Keep the answer short and concise. Respond "Unsure about answer" if not sure about the answer.

Context: Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use.

Question: What was OKT3 originally sourced from?

Answer:

输出:

Mice.

文本分类

作为提示词工程师,你需要擅长提供清晰的指令。但在更困难的用例中,仅仅提供指令是不够的,这时你需要考虑提供示例(Few-Shot Prompting)来指定正确的行为。

基础分类

提示词:

Classify the text into neutral, negative or positive.

Text: I think the food was okay.

Sentiment:

输出:

Neutral

进阶分类:指定格式

如果你希望模型返回特定的标签格式(例如小写的"neutral"而不是首字母大写的"Neutral"),可以通过提供示例来引导模型。

提示词:

Classify the text into neutral, negative or positive.

Text: I think the vacation is okay.

Sentiment: neutral

Text: I think the food was okay.

Sentiment:

输出:

neutral

注意:具体性的重要性

如果在提示词中拼写错误(如将"neutral"写成"nutral"),模型可能会忽略你的虚构标签而输出它认为正确的标签。这强调了在提示词中提供准确信息和示例的重要性。

对话

你可以通过提示工程指导大语言模型扮演特定角色,指定其行为意图和身份。这在构建客户服务聊天机器人等对话系统时非常有用,也被称为"角色提示"。

技术性回答风格

提示词:

The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.

Human: Hello, who are you?

AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of blackholes?

AI:

输出:

Sure! Black holes are regions of spacetime where the gravitational force is so strong that nothing, not even light, can escape from it. They are created when a very massive star dies and its core collapses in on itself, forming a singularity of infinite density. The intense gravity of the singularity pulls in all the matter and radiation around it, creating the black hole.

通俗易懂风格

如果你希望回答更易于理解,可以调整指令。

提示词:

The following is a conversation with an AI research assistant. The assistant answers should be easy to understand even by primary school students.

Human: Hello, who are you?

AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of black holes?

AI:

输出:

Sure! Black holes are created when a very massive star runs out of fuel and collapses in on itself. The gravity of the star is so strong that nothing, not even light, can escape its pull. This creates a point in space-time with an intense gravitational force called a black hole.

代码生成

大语言模型在代码生成方面非常有效,通过巧妙的提示,你可以执行大量的代码生成任务,甚至不需要指定编程语言。

简单程序

提示词:

/*

Ask the user for their name and say "Hello"

*/

输出:

let name = prompt("What is your name?");

console.log(Hello, ${name}!);

数据库查询生成

通过提供更多上下文(如数据库模式),模型可以生成复杂的查询。

提示词:

"""

Table departments, columns = DepartmentId, DepartmentName

Table students, columns = DepartmentId, StudentId, StudentName

Create a MySQL query for all students in the Computer Science Department

"""

输出:

SELECT StudentId, StudentName

FROM students

WHERE DepartmentId IN (SELECT DepartmentId FROM departments WHERE DepartmentName = 'Computer Science');

推理

推理是大型语言模型面临的最困难任务之一,但对于复杂应用的涌现至关重要。对于涉及数学能力的推理任务,有时需要更高级的提示词工程技术。

基础算术

提示词:

What is 9,000 * 9,000?

输出:

81,000,000

复杂推理:分步思考

当模型直接回答出错时(例如判断奇偶数之和),可以通过指示模型"将问题分解为步骤"来提高准确率。

提示词:

The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.

Solve by breaking the problem into steps. First, identify the odd numbers, add them, and indicate whether the result is odd or even.

输出:

Odd numbers: 15, 5, 13, 7, 1

Sum: 41

41 is an odd number.

通过提供更好的指令并结合示例,可以显著提高模型在推理任务上的准确性。在后续章节中,我们将介绍更高级的提示工程概念和技术。

相关推荐
圆奋奋5 分钟前
大模型训练第六步:压缩优化与部署交付
人工智能·机器学习·ai训练
LabVIEW开发10 分钟前
探测器脉冲只有 500 ns,谱线要分 2048 道:LabVIEW 怎么把振动台和计数器锁在同一根时间轴上
人工智能·算法·labview
阿策小和尚16 分钟前
4.3GB 依赖树压到 284MB、五进程 500ms 退场:我把 4 万星的 Novu 塞进了 Dopame OS
人工智能·后端·架构
JonaHu17 分钟前
GPT Image 2.6 多参考图改穿搭:输入分工与参考污染排查
图像处理·人工智能·api
hhb_61818 分钟前
AI自动化工作流:一键打通业务协同壁垒
大数据·人工智能·自动化
极客先躯22 分钟前
智能体开发高级面试每日一题|2026-06-04|Agent 的规划(Planning)能力来自哪里?LLM 原生规划有哪些局限?
人工智能·面试·agent·每日一题·高级面试·智能体开发·agenticworkflow
阿策小和尚22 分钟前
把 Python 3.14 + FastAPI + Nuxt 4 压成 164MB 单包迁进 Dopame OS:4 个坑和一份真实体积账单
前端·人工智能·前端框架
极客先躯23 分钟前
智能体开发高级面试每日一题|2026-06-02|为什么说“Agent 的能力上限由 LLM 决定“?工程层面可以做哪些弥补?
人工智能·面试·大模型·llm·agent·高级面试题·智能体开发
kobesdu25 分钟前
RK3588 还是等 RK3668?一次选型窗口的取舍
人工智能·机器人·ros·slam
嗨起飞了31 分钟前
《Finerd:AI产品榜第 1 名的只读核查》
人工智能