azure-sdk-for-java: [BUG] OpenAI beta3 - error: 'function_call' was unexpected when calling getChatCompletions()
Describe the bug
Calling Azure OpenAI openAIClient.getChatCompletions() results in an error related to function_call.
Exception or Stack Trace
05:42:54.319 ERROR c.a.core.implementation.http.rest.RestProxyBase - Status code 400, "{ "error": { "message": "Additional properties are not allowed ('function_call' was unexpected) - 'messages.0'", "type": "invalid_request_error", "param": null, "code": null }}"
com.azure.core.exception.HttpResponseException: Status code 400, "{
"error": {
"message": "Additional properties are not allowed ('function_call' was unexpected) - 'messages.0'",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
"
at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:337)
at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:130)
at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:213)
at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:81)
at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:109)
at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:91)
at jdk.proxy2/jdk.proxy2.$Proxy45.getChatCompletionsSync(Unknown Source)
at com.azure.ai.openai.implementation.OpenAIClientImpl.getChatCompletionsWithResponse(OpenAIClientImpl.java:897)
at com.azure.ai.openai.OpenAIClient.getChatCompletionsWithResponse(OpenAIClient.java:294)
at com.azure.ai.openai.OpenAIClient.getChatCompletions(OpenAIClient.java:430)
To Reproduce
In a Java class…
- Create a
List<ChatMessage> messages(or receive them from a remote client) - Create a
ChatCompletionsOptionsobject - Try to call
getChatCompletions()- this will throw an error
Code Snippet
public ChatCompletions chat(List<ChatMessage> messages) {
ChatCompletionsOptions chatOptions = new ChatCompletionsOptions(messages);
// set appropriate values for various options here (removed for clarity)
// either calling or not calling `chatOptions.setFunctionCall()` results in error
return openAIClient.getChatCompletions("gpt-35-turbo", chatOptions);
}
Expected behavior
Calls to openAIClient.getChatCompletions() should be successful and return a ChatCompletions object.
Screenshots
N/A
Setup:
- OS: Microsoft Windows Server 2022 Standard
- IDE: IntelliJ IDEA 2023.2 RC (Ultimate Edition)
- Libraries:
- com.azure:azure-core:1.41.0
- com.azure:azure-ai-openai:1.0.0-beta.3
- Java version: JDK 17 (temurin-17.0.8)
- App Server/Environment: N/A
- Frameworks: micronaut-4.0.1
Additional context
This was working in the beta2 release. It is likely related to the inclusion of the new Functions feature in the beta3 release.
Information Checklist
- Bug Description Added
- Repro Steps Added
- Setup information Added
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 21 (6 by maintainers)
The work-around seems to be working for me. Thank you!
@jnunderwood @speza
Thank you for providing this information. I can reproduce it now. After investigating, it turns out it is incompatible between our azure-core serialization and
azure-search-documents’s dependencyazure-core-serializer-json-jackson.There is a temporary solution, which is to exclude the
azure-core-serializer-json-jacksonif it doesn’t impact your application.@jnunderwood You can add the below method to the client builder and add env var “AZURE_LOG_LEVEL” see how to logging.
Hi, I have been working on something that uses Azure OpenAI and Cognitive Search as part of a Msft Hackathon and have been running into the same issue.
Specifically getting this error:
I don’t get it when just using
com.azure:azure-ai-openai:1.0.0-beta.3dependency on its own.But, something goes wrong as soon as I add another stable SDK. In my case it was the
com.azure:azure-search-documents:11.5.9.