1. Learn
  2. /
  3. Courses
  4. /
  5. Developing AI Systems with the OpenAI API

Connected

Exercise

Handling the response with external API calls

To better connect your currency conversion application to other systems, you'd like to add some checks to make sure that the model has found an appropriate answer. First you check that the response has been produced via tool_calls. If that is the case, you check that the function used to produce the result was get_exchange_rate. If so, you load the currency code extracted from the user's prompt, and call the get_exchange_rate() function with the code as argument. Finally, if that produces a response, you return the response.

In this exercise, the response, the json library, and get_exchange_rate() function have been preloaded.

Instructions 1/2

undefined XP
    1
    2
  • Check that the response has been produced via tool_calls.
  • Extract the function if the previous check passed.