I always get 400 status error when using functions inside the chat completion

this code resolves to a 400 status error always, can someone help me to point out why?

const dataFromChat = await openai
    .createChatCompletion({
      messages: [
        {
          role: "user",
          content: `return this json {h: 'hello'}`,
        },
      ],
      model: "gpt-3.5-turbo-0613",
      functions: [
        {
          name: "getdata",
          description: "gets the returned data",
          parameters: {
            returnedData: {
              type: "object",
              description: "returned data object",
            },
          },
        },
      ],
    })

Try this:

{
        name: "get_object",
        description: "Get object data from user text",
        parameters: {
            type: "object",
            properties: {
                returnedData: {
                    type: "string",
                    description: "Object data, e.g. { value: 'test'}",
                },
            },
            required: ["returnedData"]
        }
    }

Using your prompt: return this json {h: 'hello'} will output:

{
  role: 'assistant',
  content: null,
  function_call: {
    name: 'get_object',
    arguments: '{\n  "returnedData": "{\\"h\\": \\"hello\\"}"\n}'
  }
}
2 Likes

Also look at the response body and you’ll get a descriptive error message.