Custom API Plugin

If you want to make a third-party API call using your LLM, you can utilize the Custom API plugin. This feature allows you to establish a connection between your LLM and your organization's infrastructure.

Plugins work more reliably in GPT-4 and GPT-3.5-Turbo-0613

The custom API node has the following parameters:

  • Method: specifies if the request is GET or POST.

  • Params: Specifies how to send parameters (As a body or as part of the path)

  • URL: The URL basepath for the API.

  • Command: the command used by the LLM to call this API.

    • For "body" params: specify a specific JSON body.

    • For "path" params: list all the params of the API and their description.

  • Example: an example of how the LLM will specify the parameters in the "args"

  • Headers: a JSON with the request headers needed to perform the call.

The values of "command" and "example" must be consistent for the plugin to be called correctly.

Tutorial: Calling the US Federal Reserve API

To explore this feature, we will use it to enable our LLM to load data from the federal reserve API. To achieve this, we will follow these steps:

  1. Determine the API URL.

  2. Determine the request type.

  3. Find the parameters of the API.

  4. Build a description of the API for the Plugin.

First, let's determine the API URL. We need to visit the Federal Reserve API website

There we find that each request has the following structure:

https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v1/accounting/od/rates_of_exchange?fields=country_currency_desc,exchange_rate, record_date&filter=record_date:gte:2015-01-01

Here we can determine the following:

  • The API accepts GET requests.

  • The URL is: https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v1/accounting/od/rates_of_exchange

  • The parameters are set in the path.

  • The parameters available are:

    • Fields (a comma-separated list of values to load, including country_currency_desc,exchange_rate, and record_date).

    • Filters (a string filter over the fields loaded).

  • The request does not need additional headers.

Now we can connect a Custom API node to the LLM:

With the information above, we can get the fields setup as follows:

  1. Method: GET

  2. Params: Path

  3. URL: https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v1/accounting/od/rates_of_exchange

  4. Command: the command must specify the different path parameters to use, leading to: API: "api", args: "fields": "<A comma separated list of fields from country_currency_desc, exchange_rate, and record_data>", "filters": "<(OPTIONAL) a string filter on one of the fields (formatted as field:operation:value)>"

  5. Example: following the default example and the command, we set an example of invoke-tool: {'name': 'api', 'args': {'fields': 'exchange_rate,record_data', 'filters': 'record_data:gte:2015-01-01'}}

  6. Instruction: we set "use this tool to call the federal reserve API and read up-t0-date the rates of exchange".

Now we have completed all the steps needed to enable our LLM to call the federal reserve API:

Last updated