Call my api in assitanse calling

i develop a bot that help the customer adding items to his basket.
i want to add function calling that will retrive the items from the db so the “bot” will know what items i have.

in my custom gpt i used actions for that

{
	"openapi": "3.1.0",
	"info": {
		"title": "Get Contacts data",
		"description": "Retrieves contact from API.",
		"version": "v1.0.0"
	},
	"servers": [
		{
			"url": "urlForMyCustomAPI"
		}
	],
	"paths": {
		"/GetContacts.ashx": {
			"get": {
				"description": "Get all contacts from DB",
				"operationId": "GetContacts",
				"parameters": [],
				"deprecated": false
			}
		},
		"/AddContact.ashx": {
			"get": {
				"description": "Add Contact To DB",
				"operationId": "AddContact",
				"parameters": [
					{
						"name": "name",
						"in": "query",
						"description": "the name of the contact to add",
						"required": true,
						"schema": {
							"type": "string"
						}
					},
					{
						"name": "mobile",
						"in": "query",
						"description": "the mobile/phone of the contact to add",
						"required": true,
						"schema": {
							"type": "string"
						}
					},
					{
						"name": "email",
						"in": "query",
						"description": "the email of the contact to add",
						"required": true,
						"schema": {
							"type": "string"
						}
					},
					{
						"name": "address",
						"in": "query",
						"description": "the adress of the contact to add",
						"required": false,
						"schema": {
							"type": "string"
						}
					}
				],
				"deprecated": false
			}
		},
		"/UpdateContact.ashx": {
			"get": {
				"description": "Update Contact In DB",
				"operationId": "UpdateContact",
				"parameters": [
					{
						"name": "id",
						"in": "query",
						"description": "the id of the contact to update",
						"required": true,
						"schema": {
							"type": "integer"
						}
					},{
						"name": "name",
						"in": "query",
						"description": "the name of the contact to update",
						"required": true,
						"schema": {
							"type": "string"
						}
					},
					{
						"name": "mobile",
						"in": "query",
						"description": "the mobile/phone of the contact to update",
						"required": true,
						"schema": {
							"type": "string"
						}
					},
					{
						"name": "email",
						"in": "query",
						"description": "the email of the contact to update",
						"required": true,
						"schema": {
							"type": "string"
						}
					},
					{
						"name": "address",
						"in": "query",
						"description": "the adress of the contact to update",
						"required": false,
						"schema": {
							"type": "string"
						}
					}
				],
				"deprecated": false
			}
		},
		"/DeleteContact.ashx": {
			"get": {
				"description": "Delete Contact In DB",
				"operationId": "DeleteContact",
				"parameters": [
					{
						"name": "id",
						"in": "query",
						"description": "the id of the contact to delete",
						"required": true,
						"schema": {
							"type": "integer"
						}
					}
				],
				"deprecated": false
			}
		}
	},
	"components": {
		"schemas": {}
	}
}

Hi!

What’s the question?
Do you need help with a specific error that you are getting or do you need help starting out with writing tool calls for the assistants API?

Here are the docs for function calling with the assistants API.

when i try to put the same json on assitanse “add function” i get an error
that i dont have a function name.

what need to be the structure for the function?

You need to cross check the link I provided above. The structure of a function definition is different for the assistants API compared to the specification for the GPT builder.

I suggest you rewrite it in the required format for a single example function and then see if the error still occurs.

i dont undestand, who run the function?
i want the that my assitance will get the items that he can provide to the user from the db thrwo my api. so i need that the function will know ehere is my api. in the examples there only statment for functions but not the real endpoint to run

example in documantation

{
        "name": "get_current_temperature",
        "description": "Get the current temperature for a specific location",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g., San Francisco, CA"
            },
            "unit": {
              "type": "string",
              "enum": ["Celsius", "Fahrenheit"],
              "description": "The temperature unit to use. Infer this from the user's location."
            }
          },
          "required": ["location", "unit"]
        }
      }

Assistant determines which tools need to be called.
However, whether the tool calls an API or handles a local DB, you have to implement what the tool actually does.

When using the Assistant API, functions are defined as features of the tool.

https://platform.openai.com/docs/assistants/tools/function-calling/step-1-define-functions

sorry, but i still dont undestand.
if my api (for example) has a function for calculate the sum of two numbers x,y

i want to say to the assitanse that i have an api that calculate sum of two numbers the api endpoint is my.custo.url and the path is calcsum.ashx and it’s need to get two parameters (x,y) via post and the response is json with the sum.

how i do it in function declaration?

You need to provide the actual API server.
Excuse my laziness in using ChatGPT’s answer.


import requests

def calculate_sum(x, y):
    # Use the correct protocol (http or https) and your actual domain
    url = 'https://my.custo.url/calcsum.ashx' 
    data = {'x': x, 'y': y}
    response = requests.post(url, data=data)
    if response.status_code == 200:
        result = response.json()  # Assuming the response is a JSON containing the sum
        return result.get('sum')  # Adjust this if the key in the JSON response is different
    else:
        return f"Error: {response.status_code}"

Explanation:

  • Importing Requests: This library allows you to easily make HTTP requests.
  • Function Definition: The calculate_sum function takes two parameters, x and y, which are the numbers you want to sum.
  • API Endpoint: The url variable should be set to your API endpoint.
  • Data Payload: The numbers are packaged into a dictionary, which will be sent as form data in the POST request.
  • Making the POST Request: requests.post(url, data=data) sends the POST request to the server with the numbers as data.
  • Handling the Response: The server’s response is assumed to be JSON. The function parses this JSON to extract the sum.
  • Error Handling: If the API call fails (e.g., due to network issues or server errors), the function returns an error message with the HTTP status code.
  • Make sure to replace ‘https://my.custo.url/calcsum.ashx’ with the actual URL of your API and adjust how you access the sum in the JSON response based on the actual structure of the response from your API.