Why is the way to run Actions in Custom GPT different in the chat itself and in the API? need help

Hey friends
For two hours I tried to connect to my Todoist API through my custom GPT to pull my open task list and create a personal assistant.
After I finally succeeded - I accessed the Assistant section in Openai Playground in order to create the same connection to the Todoist API here as well so that I could build an automation for the Assistant in the API.

I went into actions and only then noticed that it is different from the actions that appear in Custom GPT and the writing is not in Schema but in JSON.

I worked for hours on connecting this process to Custom GPT and writing the correct Schema. It turns out that it cannot work in the same way in the Functions of the Assistant at all.

I would really appreciate help on the subject - how can I take the schema that already works for me in Custom GPT and integrate it properly in the Functions of the Assistant in order to create automation for this GPT?

thank you so much friends!

Check this post how to convert your schema to function calling

1 Like

ok thanks for the answer!
where do I use this function you showed to automatically convert it to function?
thanks!

Let us assume this is your schema

const schema = {
    "openapi":"3.1.0",
    "info":{
      "title":"Wolfram",
      "version":"v0.1"
    },
    "servers":[
      {
        "url":"https://www.wolframalpha.com",
        "description":"Wolfram Server for ChatGPT"
      }
    ],
    "paths": {
      "/api/v1/cloud-plugin": {
        "get": {
          "operationId": "getWolframCloudResults",
          "externalDocs": "https://reference.wolfram.com/language/",
          "summary": "Evaluate Wolfram Language code",
          "responses": {
            "200": {
              "description": "The result of the Wolfram Language evaluation",
              "content": {
                "text/plain": {}
              }
            },
            "500": {
              "description": "Wolfram Cloud was unable to generate a result"
            },
            "400": {
              "description": "The request is missing the 'input' parameter"
            },
            "403": {
              "description": "Unauthorized"
            },
            "503":{
              "description":"Service temporarily unavailable. This may be the result of too many requests."
            }
          },
          "parameters": [
            {
              "name": "input",
              "in": "query",
              "description": "the input expression",
              "required": true,
              "schema": {
                "type": "string"
              }
            }
          ]
        }
      },
      "/api/v1/llm-api": {
        "get":{
          "operationId":"getWolframAlphaResults",
          "externalDocs":"https://products.wolframalpha.com/api",
          "summary":"Get Wolfram|Alpha results",
          "responses":{
            "200":{
              "description":"The result of the Wolfram|Alpha query",
              "content":{
                "text/plain":{
                }
              }
            },
            "400":{
              "description":"The request is missing the 'input' parameter"
            },
            "403":{
              "description":"Unauthorized"
            },
            "500":{
              "description":"Wolfram|Alpha was unable to generate a result"
            },
            "501":{
              "description":"Wolfram|Alpha was unable to generate a result"
            },
            "503":{
              "description":"Service temporarily unavailable. This may be the result of too many requests."
            }
          },
          "parameters":[
            {
              "name":"input",
              "in":"query",
              "description":"the input",
              "required":true,
              "schema":{
                "type":"string"
              }
            },
            {
              "name":"assumption",
              "in":"query",
              "description":"the assumption to use, passed back from a previous query with the same input.",
              "required":false,
              "explode":true,
              "style":"form",
              "schema":{
                "type":"array",
                "items":{
                  "type":"string"
                }
              }
            }
          ]
        }
      }
    }
 }

Try this updated function

function convertSchema(inputSchema) {
    var tools = []
    
    for (var path in inputSchema) {
      var methods = inputSchema[path]
      for (var method in methods) {
        var outputSchema = {}

        var operation = methods[method]
        outputSchema.name = operation.operationId
        outputSchema.description = operation.summary
        outputSchema.parameters = {
          type: "object",
          properties: {},
          required: [],
        }
        operation.parameters.forEach(function(param) {
          outputSchema.parameters.properties[param.name] = {
            type: param.schema.type,
            description: param.description
          }
          if(param.schema.type === "array") {
            outputSchema.parameters.properties[param.name].items = {type: "string"}
          }
          outputSchema.parameters.required.push(param.name)
        })

        tools.push(outputSchema)
      }
    }
    
    return tools
  
 }

To use the function

const tools = convertSchema(schema.paths)

Output:

[
    {
      "name": "getWolframCloudResults",
      "description": "Evaluate Wolfram Language code",
      "parameters": {
        "type": "object",
        "properties": {
          "input": {
            "type": "string",
            "description": "the input expression"
          }
        },
        "required": [
          "input"
        ]
      }
    },
    {
      "name": "getWolframAlphaResults",
      "description": "Get Wolfram|Alpha results",
      "parameters": {
        "type": "object",
        "properties": {
          "input": {
            "type": "string",
            "description": "the input"
          },
          "assumption": {
            "type": "array",
            "description": "the assumption to use, passed back from a previous query with the same input.",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "input",
          "assumption"
        ]
      }
    }
  ]

Please note that the function does not cover all types so better check the output. It will at least give you an idea how to convert your schema.

1 Like

ok thank you so much!
but - I am not sure, where you use this Function? where do you write it so you get the Outpot?
I am not sure I understood
thanks!

@supershaneski any chance you could help me understand it?
thanks!

If you are coming from customGPT and you have Actions, then you probably have the Action’s JSON schema.

Actions in customGPT is synonymous to Assistants API function calling.

To help you convert your Actions to an equivalent function for Assistants API, you can use a script like the one I gave (e.g. convertSchema ). You can just call this once and just copy the output to a JSON file or string. Then attach it to your Assistants API.

Please note that this will just put your foot at the door as it will not call your external API. You still need to fetch your API (using GET or POST). When you process the Run and get requires_action status, you will get the following:

let completed = false

do {

const run = await openai.beta.threads.runs.retrieve(threadId, runId)

if(run.status === 'requires_action') {
      const tool_calls = run.required_action.submit_tool_outputs.tool_calls
      
      let tool_outputs = []

      tool_calls.forEach((tool) => {

                    const tool_args = JSON.parse(tool.function.arguments)
                    
                     let tool_output = { status: 'error', message: 'function not found'}

                    if(tool.function.name === 'getWolframCloudResults') {
                          // tool_args: { input: '...' }
                          const response = fetch(`https://www.wolframalpha.com/api/v1/cloud-plugin?input=${tool_args.input}`)
                          tool_output = await response.json()
                    } else if(tool.function.name === 'getWolframAlphaResults') {
                          // tool_args: { input: '...' , assumtion: [...] }
                         const response = fetch(`https://www.wolframalpha.com/api/v1/llm-api?input=${tool_args.input}&assumption=${tool_args.assumption}`)
                          tool_output = await response.json()
                    }

                    tool_outputs.push({
                        tool_call_id: tool.id,
                        output: JSON.stringify(tool_output)
                    })

    }
    
   // send back output
   await openai.beta.threads.runs.submitToolOutputs(
            threadId, 
            runId,
            {
                tool_outputs: tool_outputs,
            }

} else if(run.status === 'completed') {
      // handle completed
     completed = true
} else {
      // ...
}

await sleep(1000)

} while(!completed)

@supershaneski
You are wonderful and your answer is amazing.
But, I’m asking the simplest question because I’m a beginner - where do you run this script so that it turns your schema into a file that will fit the assistant?
Where physically do you do this operation where you write this script to turn the schema into JSON that will match the assistant API?
Where do you write the request to convertSchema?
Where do you put the schema code, click on some action and get JSON that corresponds to the assistant API?

Thank you!

It is just a script you can run anywhere to extract the function definitions of your schema then save the output as JSON file or stored as JSON string.

I do not know your workflow. If you are creating your Action schema dynamically, then you might want to include it to also output the function to be used in your Assistants so that whenever you update your Actions, it is reflected in the function definitions.

where is everywhere??
just PLESAE give me 1 example where can I run this script…
where do you run it?
where?
on browser?
on notepad?

Yes, the simplest way is to run it in a browser.