The standard formatting for generating a response from ChatGPT is a list of messages, each of which includes a ‘role’ and ‘content’. Here’s a minimal example:
```
messages = [
{“role”: “system”, “content”: “You are ChatGPT, a large language model.”},
{“role”: “user”, “content”: “Who won the world series in 2020?”},
]
response = openai.ChatCompletion.create(
model=“gpt-3.5-turbo”,
messages=messages
)
```
The ‘role’ field can be one of three values: ‘system’, ‘user’, and ‘assistant’. Typically, a conversation begins with a ‘system’ role to set the behavior of the assistant, followed by alternating ‘user’ and ‘assistant’ messages. The ‘user’ role denotes an instruction from the user, while the ‘assistant’ role denotes what the assistant previously said.
The content of a ‘system’ message is a special instruction that guides the model’s behavior, a ‘user’ message contains a user’s instruction to the assistant, and an ‘assistant’ message holds the model’s previous responses.
The ‘model’ parameter determines which version of GPT you want to use. As of March 1, 2023, `gpt-3.5-turbo` is recommended for most use cases.
After running the code, the assistant’s reply can be extracted with `response[‘choices’]0[‘message’][‘content’]`.