I see invalid_request_error on the Step 4 of the example code in this document.
In step 4, message (which is obtained from response["choices"][0]["message"]) is sent back to OpenAI.
That message is originally an assistant message with function_calls, but not with content, so when it is sent back without modification, the API call fails with error: “‘content’ is a required property - ‘messages.1’”.
When I modify it by setting some string value (eg. “Testing”) to the content, then it works as intended.
I’d like to know if it is a known issue, or working around like this would be okay. Clarifying things in the document would be greatly helpful.
If I understand correctly, the ChatCompleationAPI does not persists state across multiple calls.
Therefore the whole history must be contained in the Request.
If you do not send back the function_call from the assistant, the model has no way of knowing that a or which function calls was requested.
It might be able to infer that a function call was requested, but since the output generated by the model is nondeterministic, it would not be able to determine which exact request resulted in the provided result.
If you are using typescript, I think you are sending content=undefined for the message(at least that was my problem).
You need to set the content to null, at least that fixed my problem.
But in the npm package openapi@3.3.0 the interface ChatCompletionRequestMessage defines content?: string; which does not allow for null.
Therefore i modified line 60 of api.d.ts to content?: string|null; which got rid of my type errors.
Yes, you are correct! It was my initial misunderstanding. It is needed to return the results back to the final ChatCompletion call. Your post lead me to look again at the announcement page.