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

Connected

Exercise

OpenAI API message roles

You are developing a chatbot for an event management agency that will be used to facilitate networking during events.

Using the OpenAI API, you prepare a dictionary to pass as the message to the chat.completions endpoint. The message needs to have 3 roles defined to ensure the model has enough guidance to provide helpful responses.

Throughout the course, you'll write Python code to interact with the OpenAI API. Entering your own API key is not necessary to create requests and complete the exercises in this course. You can leave the placeholder "<OPENAI_API_TOKEN>" as the key in api_key.

The OpenAI package has been pre-loaded for you.

Instructions

100 XP
  • Create an OpenAI API Python client; setting your personal key is not required, you can leave the placeholder.
  • Complete the dictionary of messages with the role corresponding to each of the messages provided.