ChatGPT 提示工程 在本节中,我们将介绍关于 ChatGPT 的最新提示工程技术,包括技巧、应用、限制、论文和额外的阅读材料。 请注意,本节正在积极开发中。 主题: ChatGPT 简介 回顾对话任务 与 ChatGPT 对话 Python 笔记本 ChatGPT 简介 ChatGPT 是由 OpenAI 训练的新模型(训练详情),能够进行交互式对话。该模型经过训练,可以在对话环境中根据提示指令提供适当的响应。ChatGPT 可以帮助回答问题、建议食谱、创作特定风格的歌词、生成代码等。 ChatGPT 使用的是基于人类反馈的强化学习(Reinforcement Learning from Human Feedback, RLHF)。
在本节中,我们将介绍关于 ChatGPT 的最新提示工程技术,包括技巧、应用、限制、论文和额外的阅读材料。
请注意,本节正在积极开发中。
主题:
ChatGPT 是由 OpenAI 训练的新模型(训练详情),能够进行交互式对话。该模型经过训练,可以在对话环境中根据提示指令提供适当的响应。ChatGPT 可以帮助回答问题、建议食谱、创作特定风格的歌词、生成代码等。
ChatGPT 使用的是基于人类反馈的强化学习(Reinforcement Learning from Human Feedback, RLHF)。虽然这个模型比之前的 GPT 版本更强大(并且经过训练以减少有害和不真实的内容输出),但它仍然存在一些限制。让我们通过具体的例子来探讨其能力和局限性。
您可以在此处使用 ChatGPT 的研究预览版:链接,但为了下面的例子,我们将使用 OpenAI 实验室中的 Chat 模式。
在之前的一个指南中,我们讨论了对话能力和角色提示的相关内容。我们介绍了如何指导大型语言模型(LLM)以特定风格、意图、行为和身份进行对话。
让我们回顾一下之前的简单示例,其中我们创建了一个能够生成更技术性和科学性回应的对话系统。
提示:
The following is a conversation with an AI research assistant. The assistant tone is technical and scientific. Human: Hello, who are you? AI: Greeting! I am an AI research assistant. How can I help you today? Human: Can you tell me about the creation of black holes? AI:
从上面的例子中,我们可以看到两个重要的组成部分:
上述简单的例子很好地适用于使用 text-davinci-003. More recently, OpenAI announced the ChatGPT APIs, which is a more powerful and cheaper model called gpt-3.5-turbo was specifically built for this type of functionality (chat completions). OpenAI recommends this as their best model even for non-chat use cases. Other benefits of using the ChatGPT APIs are significant cost reduction (90%) and efficiency.
Big companies like Snap Inc. and Instacart are already integrating conversational features powered by ChatGPT on their products that range from personalized recommendations to open-ended shopping goals.
To begin demonstrating the capabilities of ChatGPT, we will use the chatbot assistant example above and discuss the results. Compared to text-davinci-003, the gpt-3.5-turbo 模型的文本补全 API。该模型使用对话格式作为输入。模型期望一系列消息作为输入,并利用这些消息生成响应。
输入:
SYSTEM: You are an AI research assistant. You use a tone that is technical and scientific. USER: Hello, who are you? ASSISTANT: Greeting! I am an AI research assistant. How can I help you today? USER: Can you tell me about the creation of black holes?
输出:
ASSISTANT: Of course! Black holes are created when a massive star runs out of fuel and collapses under its own gravity. This collapse causes the star to become incredibly dense, with a gravitational field so strong that not even light can escape it. This point of no return is known as the event horizon. Once a star crosses the event horizon, it is considered a black hole...
请注意,在上面的例子中,我简化了输入和输出,但 ChatGPT 对话完成 API 要求消息必须采用特定格式。我在这里添加了一个快照,展示如何在 OpenAI 实验室的“对话模式”下实现这个例子:

我们的例子更正式的 API 调用如下所示:
import openai openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are an AI research assistant. You use a tone that is technical and scientific."}, {"role": "user", "content": "Hello, who are you?"}, {"role": "assistant", "content": "Greeting! I am an AI research assistant. How can I help you today?"}, {"role": "user", "content": "Can you tell me about the creation of black holes?"} ] )
未来开发者与 ChatGPT 互动的方式预计会通过Chat 标记语言(简称 ChatML)来实现。
对话格式支持多轮对话,同时也支持单轮任务,类似于我们使用 text-davinci-003 所做的。这意味着我们可以使用 ChatGPT 执行与原始 GPT 模型所演示的类似的任务。例如,让我们尝试使用 ChatGPT 完成以下问答任务:
输入:
USER: Answer the question based on the context below. Keep the answer short and concise. Respond "Unsure about answer" if not sure about the answer. Context: Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use. Question: What was OKT3 originally sourced from? Answer:
输出:
ASSISTANT: Mice.
请注意,我在示例中添加了 USER and ASSISTANT 标签,以便更好地展示如何使用 ChatGPT 完成任务。这是使用实验场的示例:

更正式地说,API 调用(我只包含了请求的消息部分)如下所示:
CONTENT = """Answer the question based on the context below. Keep the answer short and concise. Respond \"Unsure about answer\" if not sure about the answer. Context: Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use. Question: What was OKT3 originally sourced from? Answer: """ response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": CONTENT}, ], temperature=0, )
根据官方 OpenAI 文档,gpt-3.5-turbo model will also be made available. For example, we can access the snapshot from March 1 gpt-3.5-turbo-0301. This allows developers to opt for specific model versions. This also means that the best practices for instructing models may change from version to version.
The current recommendation for gpt-3.5-turbo-0301 is to add instructions in the user message as opposed to the available system message.
| Description | Notebook |
|---|---|
Learn more about how to make calls to the ChatGPT APIs using the openai library. |
ChatGPT API Intro |
Learn how to use ChatGPT features using the LangChain 库的快照。 |
使用 LangChain 的 ChatGPT API |
声明:
本文件灏天文库团队进行了翻译。尽管我们力求准确,但请注意,翻译可能包含错误或不准确之处。原文档以其原始语言为准。我们不对因使用此翻译而产生的任何误解或误译负责。