azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

[BUG] Streaming does not work with Spring AI and Azure OpenAI

Open bruno-oliveira opened this issue 8 months ago • 7 comments

Describe the bug When streaming a completion, the results are still all aggregated and arrive sequentially instead of "streamed".

Exception or Stack Trace No stacktrace

To Reproduce Make a streaming call with Spring AI version 1.0.0 and observe the nature of the call is wrong, as the chunks are "blocked" somewhere deep in the Azure SDK code.

Code Snippet

 @ServiceMethod(returns = ReturnType.COLLECTION)
    public IterableStream<ChatCompletions> getChatCompletionsStream(String deploymentOrModelName,
        ChatCompletionsOptions chatCompletionsOptions) {
        chatCompletionsOptions.setStream(true);
        RequestOptions requestOptions = new RequestOptions();
        Flux<ByteBuffer> responseStream = getChatCompletionsWithResponse(deploymentOrModelName,
            BinaryData.fromObject(chatCompletionsOptions), requestOptions).getValue().toFluxByteBuffer();
        OpenAIServerSentEvents<ChatCompletions> chatCompletionsStream
            = new OpenAIServerSentEvents<>(responseStream, ChatCompletions.class);
        return new IterableStream<>(chatCompletionsStream.getEvents());
    }
Class: OpenAIClient.java

Expected behavior The response needs to be streamed instead of arriving all at once

Setup (please complete the following information):

  • OS: MacOS
  • IDE: IntelliJ IDEA 2024.1.2 (Ultimate Edition)
  • Library/Libraries: azure-ai-openai-1.0.0-beta.8.jar
  • Java version: 21
  • App Server/Environment: Standard Springboot setup
  • Frameworks: Spring Boot

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

  • [ X ] Bug Description Added
  • [ X ] Repro Steps Added
  • [ X ] Setup information Added

bruno-oliveira avatar Jun 14 '24 07:06 bruno-oliveira