GPT信息总结

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

信息总结:顾名思义,就是对一堆信息进行总结。
信息解释:这个跟改写内容有点像,但这个更偏向于解释与总结。下一章会给大家介绍更多的例子。
信息提取:提取信息里的某一段内容,比如从一大段文字中,找到关键内容,并分类。
本章会讲一下信息总结。信息总结还是比较简单的,基本上在 prompt 里加入总结 summarize 就可以了。但如果你想要一些特别的效果,不妨组合使用之前介绍的技巧,比如:

使用技巧 2,增加总结示例,让 AI 总结符合你需求的内容
使用技巧 4,增加 role,让 AI 总结的内容具有一定的风格
不过在这个场景,还有个技巧需要各位注意。

GPT信息解析

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

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

解释代码:比如你看到一段 Python 的代码,但你看不懂,你可以让 AI 解释下代码的含义。
解释论文:看某篇论文看不懂,或者论文里的某一段看不懂,你也可以让 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.

GPT写代码

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

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

撰写招聘信息
撰写电商平台的货物描述
撰写短视频脚本
甚至让它写代码都可以
像撰写招聘信息等,你只需要明确目标,将目标定得比较明确即可生成能让你较为满意的答案。本章我想聊下写代码。下面是一个让 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';

技巧 3:使用引导词,引导模型输出特定语内容
在代码生成场景里,有一个小技巧,上面提到的案例,其 prompt 还可以继续优化,在 prompt 最后,增加一个代码的引导,告知 AI 我已经将条件描述完了,你可以写代码了。

在 prompt 的最后增加 SELECT 可以很好地提示 AI 可以写 SQL 代码了。Better prompt:

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

同样的道理,如果你想让 AI 写 Python 代码,那 import 会是比较好的提示。但需要注意,这个只是告知 AI 可以写代码了,并不能告知 AI 写何种代码,你仍然需要在 prompt 里增加提示,告知 AI 要生成何种语言的代码。

在吴恩达的 ChatGPT Prompt Engineering 课程中,也提到这个技巧,只是在课程中,引导词并不是放在最后,而是在 prompt 里直接说明,让 AI 生成一个 JSON 格式的内容。课程中的例子是这样的(注意这个是 python 代码):

prompt = f"""
Generate a list of three made-up book titles along \
with their authors and genres.
Provide them in JSON format with the following keys:
book_id, title, author, genre.
"""

我简单解释下,其关键是在 prompt 里跟 AI 说明,需要 AI 按照 JSON 格式输出内容。

GPT推理

场景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 里试试。

GPT基于实例回答

场景介绍
在某些场景下,我们能比较简单地向 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

技巧 2:增加示例
如果你无法用文字准确解释问题或指示,你可以在 prompt 里增加一些案例:

Suggest three names for an animal that is a superhero.

Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: Horse
Names:

增加例子后,Output 的结果就更酷一些,或者说是接近我想要的那种风格的名字。

Gallop Guardian, Equine Avenger, The Mighty Stallion