ChatGPT API Transition Guide
Prompts to Messages
To have a more interactive and dynamic conversation with our models, you can use messages in ChatGPT instead of the old prompt-style using with completions.
Here's how it works:
-
Instead of sending a single string as your prompt, you send a list of messages as your input.
-
Each message in the list has two properties: role and content.
-
The 'role' can take one of three values: 'system', 'user' or the 'assistant'
-
The 'content' contains the text of the message from the role.
-
-
The system instruction can give high level instructions for the conversation
-
The messages are processed in the order they appear in the list, and the assistant responds accordingly.
Even basic Completions requests can be completed through ChatGPT, as you can see below:
Then |
Now |
|
|
Now, it is easier than ever to have back-and-forths with your model by just by extending the list of messages in the conversation.
'messages': [{'role':'user', 'content':'tell me a joke'},
{'role':'assistant', 'content':'why did the chicken cross the road'},
{'role':'user', 'content':'I don't know, why did the chicken cross the road'}]
System Instructions
You can also use a system level instruction to guide your model's behavior throughout the conversation. For example, using a system instruction and a message like this
'messages': [{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},
{'role':'user', 'content':'tell me a joke'},
will result in something like
{...
'message': {'role':'assistant',
'content':'Why did the chicken cross the road? To get to the other side, but verily, the other side was full of peril and danger, so it quickly returned from whence it came, forsooth!'}
...}