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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: ChatGPT