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

Connected

Exercise

Creating a dual-prompt get_response() function

The following exercises will be based on calling the chat.completions endpoint of the OpenAI API with two prompts (a system prompt and a user prompt). To prepare for this, in this exercise you will create a dual-prompt get_response() function that receives two prompts as input (system_prompt and user_prompt) and returns the response as an output. You will then apply this function to any example of your choice.

The OpenAI package has been pre-loaded for you.

Instructions

100 XP
  • Assign the role and content of each message in the messages list.
  • Try out the function by passing a system_prompt and a user_prompt of your choice.