Function Call - Complex Arrays as parameters

I see there are already threads about using simple arrays as parameters, but I can’t seem to get the syntax right for an array of objects. Here is an example of what I am trying to do:

{
    name: 'UpdateRoles',
    description:
      'This function updates the roles of users. It accepts an array of objects. Each object should include a role name, an email address, and an action that specifies whether the role should be added or removed.',
    parameters: {
      type: 'array',
      items: {
        type: 'object',
        properties: {
          rolename: {
            type: 'string',
            enum: ['role1','role2','admin']
            description: 'The name of the role to be updated.',
          },
          email: {
            type: 'string',
            description:
              'The email address of the user whose role is being updated.',
          },
          action: {
            type: 'string',
            enum: ['add', 'remove'],
            description:
              "The action to be performed. 'add' to assign the role to the user, 'remove' to remove the role from the user.",
          },
        },
        required: ['rolename', 'email', 'action'],
      },
    },
  };

This version appears to be the most JSON-schema compliant, however I have tried many different variants. Still receiving a 400 Bad Request error every time. Can only get it to work with the most simple of function calls. Any help would be greatly appreciated.

1 Like

Try this:

{
        name: 'UpdateRoles',
        description: 'This function updates the roles of users. It accepts an array of objects. Each object should include a role name, an email address, and an action that specifies whether the role should be added or removed.',
        parameters: {
            type: 'object',
            properties: {
                role_users: {
                    type: 'array',
                    items: {
                        type: 'object',
                        properties: {
                            rolename: {
                                type: 'string',
                                enum: ['role1','role2','admin'],
                                description: 'The name of the role to be updated.',
                            },
                            email: {
                                type: 'string',
                                description: 'The email address of the user whose role is being updated.',
                            },
                            action: {
                                type: 'string',
                                enum: ['add', 'remove'],
                                description: "The action to be performed. 'add' to assign the role to the user, 'remove' to remove the role from the user.",
                            },
                        },
                        required: ['rolename', 'email', 'action'],
                    },
                }
            },
            required: ['role_users'],
        },
    }

It returns like this:

{
  role: 'assistant',
  content: null,
  function_call: {
    name: 'UpdateRoles',
    arguments: '{\n' +
      '  "role_users": [\n' +
      '    {\n' +
      '      "rolename": "role1",\n' +
      '      "email": "test@email",\n' +
      '      "action": "add"\n' +
      '    },\n' +
      '    {\n' +
      '      "rolename": "admin",\n' +
      '      "email": "mike@email",\n' +
      '      "action": "remove"\n' +
      '    }\n' +
      '  ]\n' +
      '}'
  }
}
13 Likes

hey supershaneski, I have a similar problem. How could the json look like if I would need a return in which the argumenst (for each role_users) “rolename, email, action” be their own array?
Thank you very much

1 Like

Thank you @supershaneski, I have been stumped for weeks on how to return an array of objects, and your example finally made me see the light!

1 Like

This also helped me too. Good contributions, Thank you

1 Like