Custom API Tool for Custom Prompts Tutorial #25
debanjandhar12
announced in
Documentation
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Custom API Tool allows ChatGPT to make fetch (POST / GET) requests to an API Endpoint specified by you. For example, we can create a tool to allow ChatGPT to make requests to ocr.space.
The bellow fields are required for this. It is a good idea to use API docs or postman as reference for this. Here, we use the following postman doc:
![](https://private-user-images.githubusercontent.com/49021233/248496313-55a2fc83-ebe5-4db1-ae24-54070a073715.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NTE4NjcsIm5iZiI6MTcxOTY1MTU2NywicGF0aCI6Ii80OTAyMTIzMy8yNDg0OTYzMTMtNTVhMmZjODMtZWJlNS00ZGIxLWFlMjQtNTQwNzBhMDczNzE1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDA4NTkyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEyOThlYTVkOTI3ZGE4NjkwYjcyOGMwMTQwMjkxNTQyYTNiMGJiYzEwMGU4ZmViM2UxY2YwYjhjYTRmMmJlYzEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TvTZfbnzreCkAk9VLaEvI5C_nRsiAeMuGVBY4-xlKVc)
Tool Description
This tells ChatGPT what kind of input it should provide to the tool. In this case, we need the image URL (we actually need the image in base64 format - we will do the conversion later).
API Endpoint
This is the URL that will be called. In our example, it is
https://api.ocr.space/parse/image
. We can find this value from postman.Method
Here, we need to specify method type. From postman, we see it will be
POST
.Header
Here, we need to specify a JSON object representing the headers. The header described in postman can be written as
{"apikey:": "helloworld"}
.Body Type
Body can be send in two ways: 'JSON' and 'Form Data'. From postman we see the body is being send as 'Form Data'.
Body
Here, we need to specify a JSON object. From postman, we see that we need to specify the language and base64Image. Now, we the plugin allows us to access the input to tool from ChatGPT through
{{{input}}}
mustache.js variable. However, that is just the image URL! The plugin provides another variable -{{{base64:input}}}
to access the input file as base64 string. Obviously,{{{base64:input}}}
is only available when{{{input}}}
is a file URL.The plugin also provides the following variables:
{{{input}}}
{{{base64:input}}}
{{{file:input}}}
{{#eval}}...{{/eval}}
{{#eval}}new Date().getTime(){{/eval}}
can be used to get the current time stamp.It is also possible to access the above variables in the JavaScript evaluation block. For example, we can write
{{#eval}}this['base64:input'].split(',').pop(){{/eval}}
to get the base64 file string without thedata:image/jpg;base64,
part.The above variables can also be used in Headers and API Endpoint.
Finally, we have the following:
![image](https://private-user-images.githubusercontent.com/49021233/248496426-2f432b6e-e879-45ba-ab91-40c0f7beb1a6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NTE4NjcsIm5iZiI6MTcxOTY1MTU2NywicGF0aCI6Ii80OTAyMTIzMy8yNDg0OTY0MjYtMmY0MzJiNmUtZTg3OS00NWJhLWFiOTEtNDBjMGY3YmViMWE2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDA4NTkyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNlZmEzMjU2OWU2ZDlhM2M3ZDNiYzE5ZDA4MDk3MTdjZWRiZTRiZTQxZjgwNjRjYmYyYjI4MWQxZWVkMjIxZjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.THoSVLyQHyfrBW0CsTeL0XAUgWLD-t6MGki4Mkaec7s)
Demo:
![Animationbsdsdfdffsfdsads_1687260120208_0](https://private-user-images.githubusercontent.com/49021233/248496602-64bc433b-da48-4a64-bee5-9a82a93a2c6e.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2NTE4NjcsIm5iZiI6MTcxOTY1MTU2NywicGF0aCI6Ii80OTAyMTIzMy8yNDg0OTY2MDItNjRiYzQzM2ItZGE0OC00YTY0LWJlZTUtOWE4MmE5M2EyYzZlLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI5VDA4NTkyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZkMzQyMWI4ODg2ZjNhYTI1ZTUwYTlmMTUwNjFhMzYxZDY2MmMyMmIzNmU5OTFkNTVjOTNiZTljMGVmMWI1NjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.anj9QSJDsGXYYewWBFrDmt1tZ4MafLxxstz-vDiuJrg)
The above example can be imported with the prompt code bellow:
Beta Was this translation helpful? Give feedback.
All reactions