【Prompt使用场景】

场景1:问答问题(技巧1)

这个场景应该是使用 AI 产品最常见的方法。以 ChatGPT 为例,一般就是你提一个问题,ChatGPT 会给你答案,比如像这样:
在这里插入图片描述
在这个场景下,prompt 只要满足前面提到的基本原则,基本上就没有什么问题。但需要注意,不同的 AI 模型擅长的东西都不太一样,prompt 可能需要针对该模型进行微调。另外,目前的 AI 产品,也不是无所不能,有些问题你再怎么优化 prompt 它也没法回答你。以 ChatGPT 为例:

  1. ChatGPT 比较擅长回答基本事实的问题,比如问 什么是牛顿第三定律? 但不太擅长回答意见类的问题,比如问它
    谁是世界第一足球运动员?,它就没法回答了。
  2. 另外,ChatGPT 的数据仅有 2021 年 9 月以前的,如果你问这个时间以后的问题,比如
    现在的美国总统是谁?它的答案是「截至2021年9月,现任美国总统是乔·拜登(Joe Biden)。」

🔴 求助 这种直接提问的 prompt ,我们称之为 Zero-shot prompt。模型基于一些通用的先验知识或模型在先前的训练中学习到的模式,对新的任务或领域进行推理和预测。你会在高级篇看到相关的介绍,以及更多有意思的使用方法。

另外,正如我在前面基础用法一章中提到的那样,问答场景里还有一个很重要的玩法,就是多轮聊天,你可以针对某个问题,进行多轮的提问。

场景2:基于示例回答(技巧2)

场景介绍

在某些场景下,我们能比较简单地向 AI 描述出什么能做,什么不能做。但有些场景,有些需求很难通过文字指令传递给 AI,即使描述出来了,AI 也不能很好地理解。

比如给宠物起英文名,里面会夹杂着一些所谓的名字风格。此时你就可以在 prompt里增加一些例子,我们看看这个例子。

这个是没有任何示例的 Prompt:

Suggest three names for a horse that is a superhero.

Output 如下所示。第一个感觉还行,第二个 Captain 有 hero 的感觉,但 Canter 就像是说这匹马跑得很慢,感觉不太合适,而且三个都比较一般,不够酷。

Thunder Hooves, Captain Canter, Mighty Gallop

场景3:推理

场景介绍

在问答这个大场景下,还有一个子场景是推理,这个场景非常有意思,而且是个非常值得深挖的场景,prompt 在此场景里发挥的作用非常大。

如果你想用 ChatGPT API 做点什么小应用,我建议可以从这个场景入手,相对来说没有其他场景那么红海。

举个比较简单的例子,我将美国工商管理硕士的入学考试 GMAT 的一道数学题输入进了 ChatGPT:

If a real estate agent received a commission of 6 percent of the selling price of a certain house, what was the selling price of the house?
(1) The selling price minus the real estate agent’s commission was $84,600.
(2) The selling price was 250 percent of the original purchase price of $36,000.

(A) Statement (1) ALONE is sufficient, but statement (2) alone is not sufficient.
(B) Statement (2) ALONE is sufficient, but statement (1) alone is not sufficient.
(C) BOTH statements TOGETHER are sufficient, but NEITHER statement ALONE is sufficient.
(D) EACH statement ALONE is sufficient.
(E) Statements (1) and (2) TOGETHER are NOT sufficient.

这道题目的中文意思是这样的(你不妨也思考下这个题目?):

如果一个房地产经纪人的佣金是某个房子的售价的6%,那么这个房子的售价是多少?
(1)售价减去房地产经纪人的佣金为84,600美元。
(2)购买价是36,000美元,售价是购买价的250%。

(A)仅陈述(1)足以回答问题,但仅陈述(2)不能回答问题。
(B)仅陈述(2)足以回答问题,但仅陈述(1)不能回答问题。
(C)两个陈述合起来足以回答问题,但没有一个陈述单独足以回答问题。
(D)每个陈述单独足以回答问题。
(E)陈述(1)和(2)合起来不能回答问题。

它的 Output 是这样的,它会根据题目的要求去推理和运算:

Let's assume the selling price of the house is S.

According to the given information, the real estate agent's commission is 6% of S, which is 0.06S.

So, the amount received by the seller after paying the commission would be (S - 0.06S) = 0.94S.

Statement (1) tells us that 0.94S = $84,600. Solving for S, we get S = $90,000.

Therefore, statement (1) alone is sufficient to determine the selling price of the house.

Statement (2) tells us that the selling price is 250% of the original purchase price, which means S = 2.5*$36,000 = $90,000.

Therefore, statement (2) alone is also sufficient to determine the selling price of the house.

Since both statements individually provide the same answer, we can conclude that together they are also sufficient to determine the selling price of the house.

Hence, the answer is (D) EACH statement ALONE is sufficient.

翻译成中文是这样的:

假设房子的售价为S。

根据所给信息,房地产经纪人的佣金是S的6%,即0.06S。

因此,在支付佣金后卖方收到的金额为(S-0.06S)= 0.94S。

陈述(1)告诉我们,0.94S = 84,600美元。解出S,我们得到S = $90,000。

因此,陈述(1)单独足以确定房子的售价。

陈述(2)告诉我们,售价是原始购买价的250%,这意味着S = 2.5 * $36,000 = $90,000。

因此,陈述(2)单独也足以确定房子的售价。

由于两个陈述分别提供相同的答案,我们可以得出结论,它们共同足以确定房子的售价。

因此,答案是(D)每个陈述单独足以回答问题。

这个场景还比较简单,我就不在这举更多例子了,你可以将各种题目输入进 ChatGPT 里试试。

场景4:无中生有——写代码(技巧3)

场景介绍

除了回答问题外,另一个重要的场景是让 AI 根据你的要求完成一些内容生成任务,根据输出的结果差异,我将其概括为以下几个主要场景:

  1. 无中生有
  2. 锦上添花
  3. 化繁为简

本章,我们先来聊聊「无中生有」场景。顾名思义,就是让 AI 给你生成一些内容。你只需要向 AI 描述你想写的内容,AI 就会按你的要求写出该内容。比如:

  1. 撰写招聘信息
  2. 撰写电商平台的货物描述
  3. 撰写短视频脚本
  4. 甚至让它写代码都可以

像撰写招聘信息等,你只需要明确目标,将目标定得比较明确即可生成能让你较为满意的答案。本章我想聊下写代码。下面是一个让 ChatGPT 写代码的案例。

Prompt:

Create a MySQL query for all students in the Computer Science Department:
Table departments, columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]

Output:

SELECT students.*
FROM students
INNER JOIN departments
ON students.DepartmentId = departments.DepartmentId
WHERE departments.DepartmentName = 'Computer Science';

场景5:锦上添花——改写内容(技巧4)

场景介绍

除了从 0 生成内容外,你也可以先给 AI 一段已经写好的内容,然后让 AI 对其进行修改,让 AI 帮你将内容改得更好。实际的场景有如:

  1. 翻译:将中文文档翻译成英文,亦或者将英文翻译成中文。关于翻译,我还想强调,像 ChatGPT
    除了能翻译人类的语言外,还能翻译编程语言,比如将 Python 代码翻译成 Haskell 代码。
  2. 修改:修改内容的语法,甄别内容里的错别字。
  3. 润色:润色文章,将内容改成另一种风格。

本章重点介绍下润色场景,下面这是个润色的例子。

Prompt(内容来自维基百科):

Please rewrite the following sentences to make them easier to understand.
OpenAI is an American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated (OpenAI Inc.) and its for-profit subsidiary corporation OpenAI Limited Partnership (OpenAI LP). OpenAI conducts AI research with the declared intention of promoting and developing a friendly AI. OpenAI systems run on the fifth most powerful supercomputer in the world.[5][6][7] The organization was founded in San Francisco in 2015 by Sam Altman, Reid Hoffman, Jessica Livingston, Elon Musk, Ilya Sutskever, Peter Thiel and others,[8][1][9] who collectively pledged US$1 billion. Musk resigned from the board in 2018 but remained a donor. Microsoft provided OpenAI LP with a $1 billion investment in 2019 and a second multi-year investment in January 2023, reported to be $10 billion.[10]

它的 Output 是这样的:

OpenAI is a research organization that focuses on artificial intelligence (AI). It has two parts: a no

场景6:锦上添花——信息解释

场景介绍

锦上添花下的第二大的场景是信息解释。它跟改写内容有点像,但又不太一样,信息解释有可能提供超过原文内容的信息。

举几个信息解释的例子,大家应该就能理解了:

  1. 解释代码:比如你看到一段 Python 的代码,但你看不懂,你可以让 AI 解释下代码的含义。
  2. 解释论文:看某篇论文看不懂,或者论文里的某一段看不懂,你也可以让 AI 解释。

以解释代码为例,它的 prompt 是这样的(此案例来自 OpenAI 官方案例):

Explanation of what the code does:

Python 3 
def remove_common_prefix(x, prefix, ws_prefix): 
    x["completion"] = x["completion"].str[len(prefix) :] 
    if ws_prefix: 
        # keep the single whitespace as prefix 
        x["completion"] = " " + x["completion"] 
return x

以下是 ChatGPT 的 Output,它阐述了这段代码是拿来干什么的,同时还阐述了各个参数的含义:

This is a Python function called remove_common_prefix that takes in three parameters: x, prefix, and ws_prefix.

The x parameter is assumed to be a Pandas DataFrame or Series object with a column named "completion", which contains strings that may or may not start with the prefix string.

The prefix parameter is a string that represents the common prefix that needs to be removed from the beginning of each string in the "completion" column of the DataFrame.

The ws_prefix parameter is a Boolean value that indicates whether or not to keep a single whitespace character as a prefix after the common prefix has been removed.

The function modifies the "completion" column of the DataFrame by removing the prefix string from the beginning of each string in that column using the Pandas str method and string slicing. The len(prefix) : syntax is used to slice the string starting from the character that follows the prefix.

If ws_prefix is True, then the function adds a single whitespace character as a prefix to each string in the "completion" column after removing the prefix.

Finally, the modified DataFrame is returned by the function.

场景7:化繁为简——信息总结(技巧5)

场景介绍

内容生成大场景下的第二个场景是化繁为简,这个场景其实很好理解,就是将复杂的内容,转为简单的内容,一般常遇到的场景有:

  1. 信息总结:顾名思义,就是对一堆信息进行总结。
  2. 信息解释:这个跟改写内容有点像,但这个更偏向于解释与总结。下一章会给大家介绍更多的例子。
  3. 信息提取:提取信息里的某一段内容,比如从一大段文字中,找到关键内容,并分类。

本章会讲一下信息总结。信息总结还是比较简单的,基本上在 prompt 里加入总结 summarize 就可以了。但如果你想要一些特别的效果,不妨组合使用之前介绍的技巧,比如:

  1. 使用技巧2,增加总结示例,让 AI 总结符合你需求的内容
  2. 使用技巧4,增加 role,让 AI 总结的内容具有一定的风格

不过在这个场景,还有个技巧需要各位注意。

场景8:化繁为简——信息提取(技巧6)

场景介绍

介绍完信息总结,再聊聊信息提取,我认为这个场景是继场景3推理以外,第二个值得深挖的场景。这个场景有非常多的有意思的场景,比如:

  1. 将一大段文字,甚至网页里的内容,按要求转为一个表格。按照这个思路你可以尝试做一个更智能的,更易懂的爬虫插件。
  2. 按照特定格式对文章内容进行信息归类。

第二个可能比较难理解,举个 OpenAI 里的例子,它的 prompt 是这样的(为了有足够空间显示内容,我仅节选了 text 里的部分内容,完整内容,可以点击这里查看):

Extract the important entities mentioned in the article below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes
Desired format:
Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-

Text: """Powering Next Generation
Applications with OpenAI Codex
Codex is now powering 70 different applications across a variety of use cases through the OpenAI API.

May 24, 2022
4 minute read
OpenAI Codex, a natural language-to-code system based on GPT-3, helps turn simple English instructions into over a dozen popular coding languages. Codex was released last August through our API and is the principal building block of GitHub Copilot.

Warp is a Rust-based terminal, reimagined from the ground up to help both individuals and teams be more productive in the command-line.

Terminal commands are typically difficult to remember, find and construct. Users often have to leave the terminal and search the web for answers and even then the results might not give them the right command to execute. Warp uses Codex to allow users to run a natural language command to search directly from within the terminal and get a result they can immediately use.

“Codex allows Warp to make the terminal more accessible and powerful. Developers search for entire commands using natural language rather than trying to remember them or assemble them piecemeal. Codex-powered command search has become one of our game changing features.”

—Zach Lloyd, Founder, Warp

Machinet helps professional Java developers write quality code by using Codex to generate intelligent unit test templates.

Machinet was able to accelerate their development several-fold by switching from building their own machine learning systems to using Codex. The flexibility of Codex allows for the ability to easily add new features and capabilities saving their users time and helping them be more productive.

“Codex is an amazing tool in our arsenal. Not only does it allow us to generate more meaningful code, but it has also helped us find a new design of product architecture and got us out of a local maximum.”

—Vladislav Yanchenko, Founder, Machinet"""

Prompt 有点长,我解释下,它是让 AI 将文章里的重点内容进行抽离,并将其根据特定格式进行输出。要求将文章里提到的公司、人名、主题都按照 comma separated list(按逗号空格分开)的方式罗列出来。

最后的 output 是这样的:

Company names: OpenAI, Microsoft, GitHub, Pygma, Replit, Warp, Machinet
People names: Emile Paffard-Wray, Amjad Masad, Zach Lloyd, Vladislav Yanchenko
Specific topics: GPT-3, OpenAI API, Azure OpenAI Service, GitHub Copilot, Pygma, Replit, Warp, Machinet
General themes: Natural language-to-code, Productivity, Problem solving, Creativity, Learning
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孙和龚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值