Use system messages to control the AI's personality and behavior.
1# 2_system_prompt_role_playing.py
2from openai import OpenAI
3client = OpenAI()
4
5print("Using a system prompt to set the AI's role...")
6
7response = client.chat.completions.create(
8 model="gpt-4o-mini",
9 messages=[
10 {"role": "system", "content": "You are a friendly Python tutor."},
11 {"role": "user", "content": "Explain what a list comprehension is with an example."}
12 ]
13)
14
15print("\nPython Tutor's Response:")
16print(response.choices[0].message.content)No output yet...