'$.function_call' is invalid. Please help

Hello everyone, I’m trying to use the new function call:

    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo-0613",
        messages=[{"role": "user", "content": "write me an agenda of a 7 days local food trip to NYC. "}],
        functions=[
            {
                'name': 'write_travel_agenda',
                "description": "Writing agenda to disk",
                "parameters": parameter_dict
             }
        ],
        function_call='{"name": "write_travel_agenda"}',
    )

The parameters dict look like this:

{'definitions': {'Agenda': {'properties': {'afternoonAgenda': {'description': 'describe '
                                                                              'afternoon '
                                                                              'agenda',
                                                               'title': 'Afternoonagenda',
                                                               'type': 'string'},
                                           'eveningAgenda': {'description': 'describe '
                                                                            'dinner '
                                                                            'agenda',
                                                             'title': 'Eveningagenda',
                                                             'type': 'string'},
                                           'morningAgenda': {'description': 'describe '
                                                                            'morning '
                                                                            'agenda',
                                                             'title': 'Morningagenda',
                                                             'type': 'string'},
                                           'title': {'description': 'which day',
                                                     'title': 'Title',
                                                     'type': 'string'}},
                            'required': ['title',
                                         'morningAgenda',
                                         'afternoonAgenda',
                                         'eveningAgenda'],
                            'title': 'Agenda',
                            'type': 'object'}},
 'properties': {'agendas': {'description': 'agenda details',
                            'items': {'$ref': '#/definitions/Agenda'},
                            'title': 'Agendas',
                            'type': 'array'}},
 'required': ['agendas'],
 'type': 'object'}

I’m keep getting ‘$.function_call’ is invalid. from the server. What does that mean?

1 Like

It seems you getting a “Bad Request” error, because your Json schema for the parameters is not in the correct format.

It should looks like:

"parameters": {
        "type": "object",
        "properties": {
          "arg1": {
            "type": "string",
            "description": "The first argument in the schema"
          },
          "arg2": {
            "type": "number",
            "description": "The second argument in the schema"
          },
          ...
      }, "required": ["arg1", "arg2", ...]     # optional
}
1 Like

Thanks! What is the best way to define one of the parameters as input of array of dict?

I’ve got it working with the following prompt:

Call the test_Code function with the name ‘priory_Test’ and pass a dictionary with the key/value pairs: [{‘baseID : 32’ and ‘personID : 45’}, {‘strong’ : 100, ‘armor’ : 45}].

The function definition looks like this:

{
    "name": "test_Code",
    "description": "A function to test a specified code.",
    "parameters": {
        "type": "object",
        "properties": {
          "functionName": {
            "type": "string",
            "description": "The name of the created function to test, e.g. factorial, fibonacci, print, etc"
          },
          "params": {
            "type": "string",
            "description": "An array of dictionaries as parameter to pass to the function for testing, e.g. [{x1: int, y1: int}, {x2: int, y2: int }]."
          }
        },
        "required": ["functionName", "params"]
    }
}

And the output is:

‘function_call’: {‘name’: ‘test_Code’, ‘arguments’: ‘{\n “functionName”: “priory_Test”,\n “params”: “[{'baseID': 32, 'personID': 45}, {'strong': 100, 'armor': 45}]”\n}’}}, ‘finish_reason’: ‘stop’}], ‘usage’: {‘prompt_tokens’: 258, ‘completion_tokens’: 44, ‘total_tokens’: 302}}

I used a temperature setting of 0.0
And the GPT-3 model.

I hope this helps

3 Likes

I got array working. It needs to define the items additionally.

This is the syntax for:

(left out for brevity)
"params": {
            "type": "array",
            "description": "An array of strings to pass to the function for testing, e.g. ['Hello', 'World'].",
            "items" : {
                "type" : "string"
            }
          }

And for the use case of an array of dictionaries, the function definition looks like:

(left out for brevity)
"params": {
            "type": "array",
            "description": "An array of dictionaries to pass to the function for testing.",
            "items" : {
                "type" : "object",
                "properties" : {}
            }
          }

You can of course define the value types of the dictionary keys with the properties schema.

2 Likes

I’m having a lot of trouble getting arrays working, if you could take a look at my code and get it working, I will buy you a coffee:

model: 'gpt-3.5-turbo-0613',
        messages: [
            { role: 'system', content: "You are a helpful assistant that generates creative playlist ideas." },
            { role: 'user', content: "I'm trying to organize a list of songs into playlists. Based on some common moods/emotions that music tries to evoke in its listeners, generate a creative and unique playlist name and a corresponding description." }
        ],
        functions: [
            {
                name: "getNamesAndDescriptions",
                description: "Generates playlist names and descriptions",
                parameters: {
                    type: "array",
                    description: "An array of objects representing playlists",
                    items: {
                        type: "object",
                        properties: {
                            id: {
                                type: "number",
                                description: "A random five-digit number denoting the playlist id"
                            },
                            name: {
                                type: "string",
                                description: "A creative name for the playlist"
                            },
                            description: {
                                type: "string",
                                description: "A creative description of the playlist"
                            }
                        }
                    },
                    required: ["id", "name", "description"]
                },
            }                
        ],            
        function_call: "auto",
        temperature: 1.5
    })
1 Like

Nevermind, I figured it out on my own. If anybody else is having the same exact issue as me, the outermost type in parameters must be “object”. Anything within that object may have the type “array”. Example below:

const completion = await openai.createChatCompletion({
            model: 'gpt-3.5-turbo-0613',
            messages: [
                { role: 'system', content: "You are a helpful assistant that generates creative playlist ideas." },
                { role: 'user', content: "I'm trying to organize a list of songs into playlists. Based on some common moods/emotions that music tries to evoke in its listeners, generate 5 creative and unique playlist names and their corresponding descriptions." }
            ],
            functions: [
                {
                    name: "getNamesAndDescriptions",
                    description: "Generates playlist names and descriptions",
                    parameters: {
                        type: "object",
                        properties: {
                            playlists: {
                                type: "array",
                                description: "An array of objects representing playlists",
                                items: {
                                    id: {
                                        type: "null",
                                        description: "A unique identifier for the playlist, initially set to null"
                                    },
                                    playlist_name: {
                                        type: "string",
                                        description: "A creative name for the playlist"
                                    },
                                    playlist_description: {
                                        type: "string",
                                        description: "A creative description of the playlist"
                                    }
                                }
                            }
                        },
                        required: ["id", "playlist_name", "playlist_description"]
                    },
                }                
            ],            
            function_call: "auto",
            temperature: 1.2
        })
3 Likes

Bravo.

You are right, the properties key must be typed as ‘object’.

If you are getting trouble with the id of the items, then better set it as ‘integer’ with a sentinel value of -1. Usually you will validate this in the function code. GPT might be confused to read that it is initially at ‘null’.

Good luck and have fun.

2 Likes

Hey came here to solve this problem turned out it was just my structure. But I can’t find this in the docs why must properties have the key value pair “type”: “object”, what is typed as an object, is this the return value of the function? I just don’t get what it is referring to.

Thanks for providing the answer to your question. Definitely helps those of us who were hoping there would be one.