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

Connected

Exercise

Creating the get_response() function

Most of the exercises in this course will call the chat.completions endpoint of the OpenAI API with a user prompt. Here, you will create a get_response() function that receives a prompt as input and returns the response as an output, which in future exercises will be pre-loaded for you.

The OpenAI package, and OpenAI API Python client have been pre-loaded.

Instructions

100 XP
  • Create a request to the chat.completions endpoint inside the get_response() function.
  • Try out the function with a prompt that asks the model to write a poem about ChatGPT.