Skip to content

runFunction throws "'content' is a required property - 'messages.1'" error when using Azure openAI integration #540

@darkneo14

Description

@darkneo14

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

When you use runFunctions function with Azure open AI, it throws the "'content' is a required property - 'messages.1'" error with 400 error code.

const runner = openai.beta.chat.completions .runFunctions({ messages: [ { role: "user", content: what is sqauare root of 4? } ], functions: [ { "name": "calculateSquareRoot", "function": calculateSquareRoot, "description": "Calculate sqaure root of a number", "parameters": { type: 'object', properties: { number: { type: 'integer' }, } }, }, { "name": "calculateLogBase2", "function": calculateLogBase2, description: "Calculate log base 2 of a number", parameters: { type: 'object', properties: { number: { type: 'integer' }, } }, } ] })

After debugging in the library, I found the issue. The second gpt call that happens after the function call is missing the content field in the messages object -

{ model: 'gpt-3.5-turbo', messages: [ { role: 'user', content: 'what is sqauare root of 4?' }, { role: 'assistant', function_call: [Object] }, { role: 'function', name: 'calculateSquareRoot', content: '2' } ], functions: [ { name: 'calculateSquareRoot', parameters: [Object], description: 'Calculate sqaure root of a number' }, { name: 'calculateLogBase2', parameters: [Object], description: 'Calculate log base 2 of a number' } ], function_call: 'auto' }

Here you can see that messages[1].content is not present. In case of openAI call, this is null where it runs smoothly.
A simple solve is to add - params.messages = params.messages.map((message) => { message.content = message.content || null; return message; }).

To Reproduce

Code to reproduce -

use azure configuration for openAI initialisation.

const runner = openai.beta.chat.completions .runFunctions({ model: "gpt-3.5-turbo", messages: [ { role: "user", content: what is sqauare root of 4? } ], functions: [ { "name": "calculateSquareRoot", "function": calculateSquareRoot, "description": "Calculate sqaure root of a number", "parameters": { type: 'object', properties: { number: { type: 'integer' }, } }, }, { "name": "calculateLogBase2", "function": calculateLogBase2, description: "Calculate log base 2 of a number", parameters: { type: 'object', properties: { number: { type: 'integer' }, } }, } ] }) console.log(runner) const finalContent = await runner.finalContent();

Code snippets

No response

OS

macOs

Node version

node v16.14.2

Library version

^4.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions