I have tried to reproduce the “actions” I created while building my GPT in an “Assistant” and it was impossible for me to make it access to a URL to read its data (the url is a data api that updates constantly their data, so I can’t just download it and upload it as a file). Does anyone know if it can be done and how?
Have you copied the instructions as well to match with the custom GPT ?
- Basically, You need to convert your action to function/tool.
- Then add reference to the function/tool in your Instructions.
- When the function is invoked in the run, get the parameters from the tools and use it to fetch your external API endpoint.
- Submit the response back to the run.
If you have your Action schema, you can use a function like below to automatically convert it to function definition
function convertSchema(inputSchema) {
var outputSchema = {}
for (var path in inputSchema) {
var methods = inputSchema[path]
for (var method in methods) {
var operation = methods[method]
outputSchema.name = operation.operationId
outputSchema.description = operation.summary
outputSchema.parameters = {
type: "object",
properties: {}
}
operation.parameters.forEach(function(param) {
outputSchema.parameters.properties[param.name] = {
type: param.schema.type,
description: param.description
}
})
}
}
return outputSchema
}
For example, you have this schema:
...
"get": {
"summary": "Get current weather information",
"operationId": "checkWeatherUsingGET",
"parameters": [
{
"name": "location",
"in": "query",
"required": true,
"description": "Location for which to retrieve weather information.",
"schema": {
"type": "string"
}
}
],
...
It will output like this:
{
"name": "checkWeatherUsingGET",
"description": "Get current weather information",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "Location for which to retrieve weather information."
}
},
"required": ["location"]
}
}
Now, when this is invoked in the run, you’ll get something like this:
{
id: 'call_3Bf62kh5wpgzE8wjn0TvVxeA',
type: 'function',
function: {
name: 'checkWeatherUsingGET',
arguments: '{"location":"Tokyo"}'
}
}
Using the location parameter, call your endpoint
https://.../api/weather?location=Tokyo
You will receive something like this
{"location":{"name":"Tokyo","region":"Tokyo","country":"Japan","lat":35.69,"lon":139.69,"tz_id":"Asia/Tokyo","localtime_epoch":1695556336,"localtime":"2023-09-24 20:52"},"current":{"last_updated_epoch":1695555900,"last_updated":"2023-09-24 20:45","temp_c":23,"temp_f":73.4,"is_day":0,"condition":{"text":"Clear","icon":"//cdn.weatherapi.com/weather/64x64/night/113.png","code":1000},"wind_mph":20.6,"wind_kph":33.1,"wind_degree":50,"wind_dir":"NE","pressure_mb":1020,"pressure_in":30.12,"precip_mm":0,"precip_in":0,"humidity":73,"cloud":0,"feelslike_c":24.9,"feelslike_f":76.9,"vis_km":10,"vis_miles":6,"uv":1,"gust_mph":17.8,"gust_kph":28.6},"infoLink":"https://weathergpt.vercel.app/tokyo"}
Submit that as your tool output and continue the run
{
tool_call_id: 'call_3Bf62kh5wpgzE8wjn0TvVxeA',
output: JSON.stringify(api_response)
}
That should work.
quick follow up question @supershaneski - I assume there is no way to use something like your function (convertSchema) dynamically/programmatically, rather you were suggesting to generate the functions offline and hard code the function definitions, correct?
We are also struggling with 2 major issues around actions, custom GPT does not allow more than 30 operations and we have a very large API spec (300+), and converting that to functions seems very kuldgy and every time an API changes we’ll have to regenerate the schema/functions all over and redeploy a new assistant API - If anyone has other suggestions around this topic we’d be grateful.
You can probably deploy or include a similar function in your workflow. Every time you add/update an action schema that you update the associated JSON file/string of the function/tool definition by calling such convertSchema function. Then you can perhaps also include some dynamic testing to check if it works.