How to used External Url Api

The API cannot connect with the internet. It can only emit AI-produced language back to you.

You will need to code a function-call handler that receives the AI response and arguments, and then makes the API network call to the service. Your code shim then not only translates the AI-emitted parameters into actual API call parameters, but also processes the return from the API, and places it with natural language that can be understood by the AI as a new message added and re-ran.


AI designed to answer your needs:

Here’s a tool specification for the external pricing data retrieval API. This specification includes a function that the AI can call to retrieve the most current price of a tour by sending the tour ID to the specified external API.

toolspec = []

toolspec.extend([{
    "type": "function",
    "function": {
        "name": "get_tour_price",
        "description": "Retrieves the current price of a tour by sending the tour ID to an external API.",
        "parameters": {
            "type": "object",
            "properties": {
                "tour_id": {
                    "type": "string",
                    "description": "The unique identifier of the tour."
                }
            },
            "required": ["tour_id"]
        }
    }
}])

Usage Explanation

  1. get_tour_price: This function is designed to retrieve the current price of a tour. It accepts a single parameter, tour_id, which is the unique identifier of the tour. When called, this function will send the tour_id to an external API to get the latest pricing information.

With this specification, the AI will be able to respond to user inquiries regarding the price of a tour by calling this function with the appropriate tour ID and fetching the latest price from the external API.

You will have to write the code to capture the tool_call and arguments returned from the OpenAI API, and then handle sending to the pricing API.

1 Like