Trouble Converting Custom GPT to Assistant

  1. Basically, You need to convert your action to function/tool.
  2. Then add reference to the function/tool in your Instructions.
  3. When the function is invoked in the run, get the parameters from the tools and use it to fetch your external API endpoint.
  4. 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.

4 Likes