Skip to content

[BUG] azure-ai-openai 1.0.0-beta.16 breaks when custom_blocklists is enabled #48388

@RafaelAnsay

Description

@RafaelAnsay

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:

  1. add custom blocklist as shown here:
Image

Code Snippet
Here, when chat completion returns
....
...
custom_blocklists: [.....]
....
..
sdk expects an object {..} instead of array [...] and jsonReader.readObject throws an exception here:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions