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.
This exercise is part of the course
Developing AI Systems with the OpenAI API
Exercise instructions
- Call the Chat Completions endpoint and ensure the
system
is provided with instructions on how to handle the prompt.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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)