MulaiMulai sekarang secara gratis

Handling the response with external API calls

To better connect your flight simulation 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_airport_info. If so, you load the airport code extracted from the user's prompt, and call the get_airport_info() 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_airport_info() function have been preloaded.

Latihan ini adalah bagian dari kursus

Developing AI Systems with the OpenAI API

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Check that the response has been produced using function calling
if ____:
# Extract the function
    function_call = ____
    print(function_call)
else:
    print("I am sorry, but I could not understand your request.")
Edit dan Jalankan Kode