Working with the OpenAI API
James Chapman
Curriculum Manager, DataCamp
Single-turn tasks
Multi-turn conversations
→ Build on previous prompts and responses
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}]
)
messages=[{"role": "system",
"content": "You are a data science tutor who speaks concisely."},
{"role": "user",
"content": "What is the difference between mutable and immutable objects?"}]
response = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "system", "content": "You are a data science tutor who speaks concisely."}, {"role": "user", "content": "What is the difference between mutable and immutable objects?"}] )
print(response.choices[0].message.content)
Mutable objects can be changed after creation, while immutable objects cannot be
modified once they are created.
Working with the OpenAI API