1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI API

Exercise

The Chat Completion endpoint

The models available via the Chat Completions endpoint can not only perform similar single-turn tasks as models from the Completions endpoint, but can also be used to have multi-turn conversations.

To enable multi-turn conversations, the endpoint supports three different roles:

  • System: controls assistant's behavior
  • User: instruct the assistant
  • Assistant: response to user instruction

In this exercise, you'll make your first request to the Chat Completions endpoint to answer the following question:

What is the difference between a for loop and a while loop?

The openai package has been pre-loaded for you.

Instructions

100 XP
  • Assign your API key to openai.api_key.
  • Create a request to the ChatCompletion endpoint using both system and user messages to answer the question, What is the difference between a for loop and a while loop?
  • Extract and print the assistant's text response.