Utilizing systems messages
The Chat Completions endpoint supports three different roles to shape the messages sent to the model:
- System: controls assistant's behavior
- User: instruct the assistant
- Assistant: response to user instruction
In this exercise, you'll begin to design an AI system for helping people learn new skills, using a system message to set an appropriate model behavior.
This exercise is part of the course
Working with the OpenAI API
Exercise instructions
- Create a request using both system and user messages to create a study plan to learn to speak Dutch.
- Extract and print the assistant's text response.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
client = OpenAI(api_key="")
# Create a request to the Chat Completions endpoint
response = client.chat.completions.create(
model="gpt-4o-mini",
max_tokens=150,
messages=[
{"role": ____,
"content": "You are a study planning assistant that creates plans for learning new skills."},
{"____": "____",
"____": "I want to learn to speak Dutch."}
]
)
# Extract the assistant's text response
print(response.choices[0].____.____)