ChatGPT 入门教程||ChatGPT 应用场景3:推理||ChatGPT 应用场景4:生成代码

ChatGPT 应用场景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)合起来不能回答问题。

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

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

ChatGPT 应用场景4:生成代码

场景介绍

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

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

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

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

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

输入:

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

 为计算机科学系的所有学生创建MySQL查询:

Table departments, columns = [DepartmentId, DepartmentName] 
Table students, columns = [DepartmentId, StudentId, StudentName] 

输出:

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 代码了。

更好的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

 为计算机科学系的所有学生创建MySQL查询:

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 格式输出内容。

猜你喜欢

转载自blog.csdn.net/m0_69824302/article/details/131132298