1. Learn
  2. /
  3. Courses
  4. /
  5. ChatGPT Prompt Engineering for Developers

Exercise

Creating a dual-prompt get_response() function

Since the majority of 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), 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. In future exercises, this function will be pre-loaded for you.

The OpenAI package has been pre-loaded for you.

Instructions

100 XP
  • Set your API key to api_key within the OpenAI() class.
  • 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.