Coding

Explain GPT Chat API Roles and Conversation Format

Explain how GPT chat API messages, roles, conversation history, response extraction, and finish reasons work.

7 steps English

Prompt template

Run these steps in order.

01
Explain that GPT chat models receive a series of messages, each with a role ('system', 'user', or 'assistant') and content.
02
Explain that conversations typically begin with a 'system' message to set the assistant's behavior, followed by 'user' and 'assistant' messages.
03
Describe how 'user' messages provide instructions or queries from end users or developers.
04
Describe how 'assistant' messages can represent prior model responses or example outputs supplied by a developer.
05
Explain that relevant conversation history must be included with each API call because the model does not retain memory between calls.
06
Explain that conversation history must fit within the model's token limit and may need to be shortened.
07
Explain how to extract the assistant's reply from choices[0].message.content and use finish_reason to determine whether the output is complete or truncated.

Prompt library

Use these prompts directly inside ChatGPT.

Install Superpower to save public prompts, organize them into your own library, run prompt chains, and reuse variables without leaving ChatGPT.