ChatGPT Prompt Engineering
In this section, we cover the latest prompt engineering techniques for ChatGPT, including tips, applications, limitations, papers, and additional reading materials.
Topics:
ChatGPT Introduction
ChatGPT is a new model trained by OpenAI (opens in a new tab) that has the capability to interact in a conversational way. This model is trained to follow instructions in a prompt to provide appropriate responses in the context of a dialogue. ChatGPT can help with answering questions, suggesting recipes, writing lyrics in a certain style, generating code, and much more.
ChatGPT is trained using Reinforcement Learning from Human Feedback (RLHF). While this model is a lot more capable than previous GPT iterations (and also trained to reduce harmful and untruthful outputs), it still comes with limitations. Let's cover some of the capabilities and limitations with concrete examples.
You can use the research preview of ChatGPT here but for the examples below we will use the Chat
mode on the OpenAI Playground.
Reviewing The Conversation Task
In one of the previous guides, we covered a bit about conversation capabilities and role prompting. We covered how to instruct the LLM to have a conversation in a specific style, with a specific intent, behavior, and identity.
Let's review our previous basic example where we created a conversational system that's able to generate more technical and scientific responses to questions.
Prompt:
From the example above, you can see two important components:
the intent or explanation of what the chatbot is
the identity which instructs the style or tone the chatbot will use to respond
The simple example above works well with the text completion APIs that uses text-davinci-003
. More recently, OpenAI announced the ChatGPT APIs (opens in a new tab), which is a more powerful and cheaper model called gpt-3.5-turbo
was specifically built for this type of functionality (chat completions). In fact, 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.
Conversations with ChatGPT
Multi-turn Conversations
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
model that powers ChatGPT uses a chat format as input. The model expects a series of messages as input and uses those to generate a response.
Input:
Output:
Note that in the example above, I have simplified the input and output but the ChatGPT chat completion API requires messages to be in a specific format. I have added a snapshot below of how this example would look using the Chat Mode
in the OpenAI Playground:
The more formal API call for our example would look something like the example below:
In fact, the way developers interact with ChatGPT in the future is expected to be done via the Chat Markup Language (opens in a new tab) (ChatML for short).
Single-turn tasks
The chat format enables multi-turn conversations but it also supports single-turn tasks similar to what we used with text-davinci-003
. This means we can use ChatGPT to perform similar tasks as what we have demonstrated for the original GPT models. For example, let's try to perform the following question answering task using ChatGPT:
Input:
Output:
Keep in mind that I am adding the USER
and ASSISTANT
labels to better demonstrate how the task can be performed using ChatGPT. Here is the example using the Playground:
More formally, this is the API call (I've only included the message component of the request):
Instructing Chat Models
According to the official OpenAI docs, snapshots of the 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.
References
Introducing ChatGPT (opens in a new tab) (Nov 2022)
Last updated on April 16, 2023
Last updated