Calling an external API
Now that you have a clearly structured function definition, you move on to improving your endpoint request. You use the Chat Completions endpoint and pass a system message to ensure that the AI assistant is aware that it is in the aviation space and that it needs to extract the corresponding airport code based on the user input.
In this exercise, the get_airport_info() function has been preloaded. The get_airport_info() function uses the AviationAPI and takes as input one airport code, returning the response with the requested airport information. The print_response() function has also been preloaded to print the output.
Latihan ini adalah bagian dari kursus
Developing AI Systems with the OpenAI API
Petunjuk latihan
- Call the Chat Completions endpoint and ensure the
systemis provided with instructions on how to handle the prompt.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
client = OpenAI(api_key="")
# Call the Chat Completions endpoint
response = ____(
model="gpt-4o-mini",
messages=[
____,
{"role": ____, "content": "I'm planning to land a plane in JFK airport in New York and would like to have the corresponding information."}],
tools=function_definition)
print_response(response)