-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
SDK breaks when custom_blocklists is enabled
***Exception or Stack Trace***
java.io.UncheckedIOException: java.io.IOException: java.lang.IllegalStateException: Unexpected token to begin object deserialization: START_ARRAY
at com.azure.core.implementation.serializer.DefaultJsonSerializer.deserializeFromBytes(DefaultJsonSerializer.java:34)
at com.azure.core.implementation.util.FluxByteBufferContent.toObject(FluxByteBufferContent.java:100)
at com.azure.core.util.BinaryData.toObject(BinaryData.java:1117)
at com.azure.core.util.BinaryData.toObject(BinaryData.java:928)
at com.azure.ai.openai.OpenAIClient.getChatCompletions(OpenAIClient.java:761)
at org.springframework.ai.azure.openai.AzureOpenAiChatModel.lambda$internalCall$1(AzureOpenAiChatModel.java:268)
at io.micrometer.observation.Observation.observe(Observation.java:565)
at org.springframework.ai.azure.openai.AzureOpenAiChatModel.internalCall(AzureOpenAiChatModel.java:264)
To Reproduce
Steps to reproduce the behavior:
- add custom blocklist as shown here:
Code Snippet
Here, when chat completion returns
....
...
custom_blocklists: [.....]
....
..
sdk expects an object {..} instead of array [...] and jsonReader.readObject throws an exception here:
Line 76 in cf85ead
| return jsonReader.readObject(reader -> { |
ContentFilterDetailedResults fromJson
public static ContentFilterDetailedResults fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
boolean filtered = false;
List<ContentFilterBlocklistIdResult> details = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("filtered".equals(fieldName)) {
filtered = reader.getBoolean();
} else if ("details".equals(fieldName)) {
details = reader.readArray(reader1 -> ContentFilterBlocklistIdResult.fromJson(reader1));
} else {
reader.skipChildren();
}
}
return new ContentFilterDetailedResults(filtered, details);
});
}Probably need to use jsonReader.readArray?
Expected behavior
Should work OK
Setup (please complete the following information):
- Anything that uses azure-ai-openai 1.0.0-beta.16
Misc
This is probably related: spring-projects/spring-ai#5537
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added