1. 学习
  2. /
  3. 课程
  4. /
  5. Developing AI Systems with the OpenAI API

Connected

练习

Defining a function with external APIs

You are developing a currency conversion application and have been asked to develop a system that provides exchange rate information based on users' requests. You decide to use the OpenAI API to extract the relevant currency code from the user's message, and then call the ExchangeRate API to return the latest rates. As the first step in your coding project, you configure the function to pass to the tools parameter in the Chat Completions endpoint.

In this exercise, the get_exchange_rate() and get_response() functions have been preloaded. The get_exchange_rate() function uses the ExchangeRate API and takes as input one currency code, returning the response with the requested exchange rate information.

说明

100 XP
  • Define the function to pass to tools: that should include the function 'name' for the function, a 'description' specifying that a matching currency code should be returned, and 'parameters' and 'result' details.