1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI Responses API

Connected

Exercise

Integrating Function-Calling Tools

You've created a timezone conversion tool using the convert_timezone() function and defined it in OpenAI's tool format. Now you need to implement the complete function-calling workflow. The client is already initialized, and the tools list contains your timezone conversion tool definition. The convert_timezone() function is also ready to use.

A messages list has been started containing a user input that requires the timezone information from your convert_timezone tool.

Instructions

100 XP
  • Loop through the response output items from the first Responses request to check if contains a 'function_call' to 'convert_timezone'; then call convert_timezone() on the unpacked arguments from the item, storing the result in timezone_result.
  • Add a message of type 'function_call_output' to the messages list containing the result from convert_timezone().
  • Create the final Responses request with the messages containing the function result and, again, passing the tools list.