Working with the OpenAI API
James Chapman
Curriculum Manager, DataCamp
client = OpenAI(api_key="<OPENAI_API_TOKEN>")
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "..."}]
)
print(response.choices[0].message.content)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "..."}],
max_completion_tokens=20,
temperature=0.5
)
max_completion_tokens
and temperature
"system"
"assistant"
AI application development:
Apply your learning in projects:
Working with the OpenAI API