Context
Applications using AI often use a UI that generates text little by little in a stream instead of outputting texts all at once. The current spring-ai AiClient
does not support stream output.
Expected Behavior
I hope that generateStream
method will be added to AiClient
. As for the return value, Flux<AiResponse>
is promising, but if you want to avoid dependence on reactor, you can also consider the JDK standard Flow.Publisher<AiResponse>
.
For example, openai-java used in OpenAiClient
uses Flowable
. This can be converted to Flux
or Flow.Publisher
.
https://github.com/TheoKanning/openai-java/blob/650d76b87a3246a52247b231f8d47f994ae63020/service/src/main/java/com/theokanning/openai/service/OpenAiService.java#L150
This is a little off topic, but openai-java uses outdated RxJava2 and has an unnecessary number of dependencies (e.g. kotlin sdk). Since spring-ai does not use all OpenAI APIs, I think it is better to have an in-house OpenAI client that implements only the minimum API with WebClient
that supports the streaming.
Comment From: making
fixed via https://github.com/spring-projects/spring-ai/commit/e30be94a564fe751bf2a2e316925d8cb12ba2224