October 10, 2023
GET API tool
We’ve added support for a tool that can make GET calls to an external API.
This can be used to dynamically retrieve context for your prompts. For example, you may wish to get additional information about a user from your system based on their ID, or look up additional information based on a query from a user.
To set up the tool you need to provide the following details for your API:
Define your API
First you will need to define your API. For demo purposes, we will create a mock endpoint in postman. Our mock endpoint simply returns details about a mock user given their user_id
.
A call to our Mock API in Python is as follows; note the query parameter user_id
And returns the response:
We can now use this tool to inject information for a given user into our prompts.
Set up the tool
Navigate to the tools tab in your organisation and select the Get API Call
tool card:
Configure the tool with your API details:
Use the tool
Now your API tool is set up, you can use it to populate input variables in your prompt templates. Double curly bracket syntax is used to call a tool in the template. The call signature is the unique tool name with arguments for the query parameters defined when the tool was set up.
In our mock example, the signature will be: get_user_api(user_id)
.
An example prompt template using this tool is:
The tool requires an input value to be provided for user_id. In our playground environment the result of the tool will be shown populated top right above the chat:
What’s next
Explore more complex examples of context stuffing such as defining your own custom RAG service.