Chat Completion Message Content + Function_Call

Hello,

I want to create a completion containing a function call. It works but the issue is that when the response contains a function call the content of the response message is always null.
It seems like the API doesn’t return a message when there’s a function call but only when there’s no function call.
I want to have both a message.content and a function)call

const completion = await openai.createChatCompletion({

  • model: model,*
  • messages: messages,*
  • temperature: 0,*
  • max_tokens: 150, // Set the maximum token length as needed*
  • functions: functionDescriptions,*
  • function_call: “auto”*
  • });*

Output:
[
{
index: 0,
message: { role: ‘assistant’, content: null, function_call: [Object] },
finish_reason: ‘function_call’
}
]

Same issue appears when I use Python or API call without SDK.

Thank you for help

Hi and welcome to the Developer Forum!

This is the standard behaviour of a function call, why would you want a message content as well as the function content in a single call?

I think this is how it works…

One solution I can think of is maybe trying convert your function call prompt to a regular instructional prompt, asking for a json as a result that would include the parameters to your function call, in addition to the message you want.

The flow is:

User query

AI checks query and decides if to use a function to achieve the users query goal.

If a function call is needed the model sets the return type to function and passes the parameters for that function call as a json object.

Your code then executes that function call and generates a response.

Response along with the function call object is then inserted back into the message chain and then the model generates a human friendly response, using a total of 2 API calls.

3 Likes

It was possible early on with the function-calling model to work against the training, and get both a “content” message and a “function_call”. An elaborate version of “explain your methods first, and only after producing that preliminary statement, use API tool functions to fulfill the request”.

I have not found a way to make that reliably work now. You have to let the AI answer after it has used and been informed by the functions it wants.

In fact, most mentions of functions will make the function operation poorer.

It is the standard mode of function calling. The content will be null if a function call is matched.

Hi, thank you for your reply.

I have a chatbot AI-assistant that tells the user how to do something and offers to function it on their behalf.
So, first I need the content to guide the user how to do it manually. Also, suggest that the AI-assistant can do it on confirmation.

The best way would be to just make a normal API call for the manual “how-to” and then make a function call afterwards with the function_call parameter set to the function name to force a function call if the user chooses to use it.