如何使用ChatGPT,才能得到高质量的回答
大家都知道,ChatGPT 是 AIGC 的一种,它还没有人那么聪明。
它的回答与你给出的提示语质量有强相关。
本文就是我给你准备的一个密方。
1
原则一:写清楚且具体的指示。
技巧一:使用分隔符。例如,
三个双引号:"""
三个反引号:```
三个短横线:---
一对尖括号:< >
XML 的tag:<tag> </tag>
例如,下面将代码的编写要求使用 ```进行分隔。
suppose you are a senior python developer engineer. There is a requirement as following.
```
Given there is a image,
Please crop a new image out of the original image.
The input is image filename and 4 integers(x1,y1,x2,y2 ).
x1 and y1 represent the point of top-left.
x2 and y2 represent the point of bottom-right.
The program should check whether the image exists or not. If not, show a warning message and exit.
The program should check whether the two points top-left and bottom-right are integers and located in the images. If not, show a warning message which image size and exit.
```
could you give me the python program which could take params in commandline.
技巧二:给出你所要求的输出格式。
例如 HTML,XML,Json,Markdown。例如:
上面引用的完整文字在这里。https://book.douban.com/review/14546670/
ChatGPT 生成的答案如下所示。
如果没有提示词中的第一句“总结下面的文字,使用Markdown 格式,并且最多使用 5 个 bulletpoint。”,那么生成的答案一是比较文字多,结构化不好,同时也没有重点提示。
技巧三:要检查你提出的条件是否满足,前提假设是否满足。
由于ChatGPT 是生成式的,有一个参数是“温度”。所以,给出的答案并不一定完全正确。所以,需要自行检查。
技巧四:给出少量的训练提示。例如给出一个简单的结果输出的例子,然而再问问题。例如:
你的任务是以一致的答题方式来回答。例如:
<小学生>:请告诉我,什么是“耐心”?
<老师>: 耐心就是指心里不急躁,不厌烦;指不急躁、不厌烦的性格。
<小学生>:请告诉我,什么是“谦虚”?
ChatGPT的输出如下所示:
原则二:给ChatGPT 一些思考时间
技巧一:指定完成一个任务的具体步骤,例如:
Step 1:……
Step 2:……
Step 3:……
……
Step N:……
例如,下面的提示语:
按顺序执行下面的一系列任务:
1 - 用一句话总结文本内容,并用三个单引号包围。
2 - 把它翻译成英文。
3 - 在这个总结性的英文中,列出提到的第一个人名。
4 - 使用json格式输出,包含关键字:summumry ,person_name。
你的每个答案使用两个空行分隔。
正文如下:
```
blah blahblahblahblah
blahblahblahblahblahblahblah
```
技巧二:不要急于得到答案,而是指导 ChatGPT 让它思考后,再给出它自己的答案.
比如,你出了一道数学题,并且你的学生做了一个答案。那么,你就可以使用下面的提示语。
你的任务是判断上面这个学生的答案是否正确。
为了回答这个问题,你应该遵守下面的步骤:
- 首先,你自己找到这个题目的答案。
- 其次,将你的答案与学生的答案进行对比,并评估这个学生的答案是否正确。
注意,只有你自己先解答这个题目,才能评估这个学生的答案。
回答问题使用下面的格式:
1. 问题:
```
问题内容写在这里。
```
2. 学生的答案:
```
学生的答案内容写在这里。
```
3. 你的答案
```
一步一步地写出你的答案,需要解题的推理过程。
```
4. 学生的答案是否与你答案相同?
```
是 或 不是
```
===
好,问题如下。
===
1. 问题:
blah blahblah
2. 学生的答案:
blah blah blah
blah blah blah
blah blah blah
如果你不想使用https://chat.openai.com/ 的 Web 对话框方式,也可以自己编写代码,通过 API 与其进行交互。
可以按下面步骤来做一个简单的 Demo,尝试一下。
2
2.1 使用 OpenAI API 的前提条件
你有openAI的账号
设置了付费计划。访问
https://platform.openai.com/account/billing/payment-methods,
并如下点击设置。
2.2 安装 API
pip install openai
2.3 打开 openai API Key
打开 https://openai.com/,用账号登录,
访问 https://platform.openai.com/docs/api-reference/authentication,点击“API Keys ”
2.4 创建 API Key
2.4.1 开打创建页面
2.4.2 输入一个好记的名字
2.4.3 复制自动生成的Key
2.5 将 Secret Key 设置为环境变量
export OPENAI_KEY="sk-xdtD ……aZlD9n"
2.6 编写Python的函数 get_completion
import openai
import os
openai.api_key = os.environ.get("OPENAI_KEY")
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [
{
"role":"user",
"content":prompt
}
]
response = openai.ChatCompletion.create(
model = model,
messages = messages,
temperature = 0,
)
return resopnse.choices[0].message["content"]
2.7 调用 get_completion , 与openai 交互
text = f"""
Given there is a image,
Please crop a new image out of the original image.
The input is image filename and 4 integers(x1,y1,x2,y2 ).
x1 and y1 represent the point of top-left.
x2 and y2 represent the point of bottom-right.
The program should check whether the image exists or not. If not, show a warning message and exit.
The program should check whether the two points top-left and bottom-right are integers and located in the images. If not, show a warning message which image size and exit.
"""
prompt = f"""
suppose you are a senior python developer engineer. There is a requirement as following.
```{text}```
could you give me the python program which could take params in commandline.
"""
response = get_completion(prompt)
print(response)
乔梁老师开课啦~视频课程《持续部署训练营(Python版)》,原价1699元, 限时特价699元
你的软件开发效率够高吗?质量够好吗?你的团队多长时间才能向用户实时推送一个生产变更?你的软件在发布时,你是否因担心软件交付质量而感到压力倍增?你是否遇到过部署失败,甚至导致停机的情况?持续部署可以帮助你消除软件交付的痛苦,让你能专注于为客户高价值的需求,而不会因为这些交付执行类问题而花太多精力。本课程通过学练结合,理论结合实战,让你体验如何使用构建-测试-部署管道,进行持续部署。并练习如何在有效监控部署的同时,逐步发布功能特性,并作数据库结构变化。
(扫码订阅)