Skip to content

Commit 18129a3

Browse files
committed
fix: Incorrect outputModalities judgment in stream mode
Signed-off-by: YunKui Lu <luyunkui95@gmail.com>
1 parent 694bb50 commit 18129a3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatModel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ public Flux<ChatResponse> internalStream(Prompt prompt, ChatResponse previousCha
271271
return Flux.deferContextual(contextView -> {
272272
ChatCompletionRequest request = createRequest(prompt, true);
273273

274-
if (request.outputModalities() != null) {
275-
if (request.outputModalities().stream().anyMatch(m -> m.equals("audio"))) {
276-
logger.warn("Audio output is not supported for streaming requests. Removing audio output.");
277-
throw new IllegalArgumentException("Audio output is not supported for streaming requests.");
278-
}
274+
if (request.outputModalities() != null
275+
&& request.outputModalities().contains(OpenAiApi.OutputModality.AUDIO)) {
276+
logger.warn("Audio output is not supported for streaming requests. Removing audio output.");
277+
throw new IllegalArgumentException("Audio output is not supported for streaming requests.");
279278
}
279+
280280
if (request.audioParameters() != null) {
281281
logger.warn("Audio parameters are not supported for streaming requests. Removing audio parameters.");
282282
throw new IllegalArgumentException("Audio parameters are not supported for streaming requests.");

models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/OpenAiChatModelIT.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,7 @@ void multiModalityOutputAudio(String modelName) throws IOException {
551551

552552
@ParameterizedTest(name = "{0} : {displayName} ")
553553
@ValueSource(strings = { "gpt-4o-audio-preview" })
554-
void streamingMultiModalityOutputAudio(String modelName) throws IOException {
555-
// var audioResource = new ClassPathResource("speech1.mp3");
554+
void streamingMultiModalityOutputAudio(String modelName) {
556555
var userMessage = new UserMessage("Tell me joke about Spring Framework");
557556

558557
assertThatThrownBy(() -> this.chatModel
@@ -564,6 +563,16 @@ void streamingMultiModalityOutputAudio(String modelName) throws IOException {
564563
.build()))
565564
.collectList()
566565
.block()).isInstanceOf(IllegalArgumentException.class)
566+
.hasMessageContaining("Audio output is not supported for streaming requests.");
567+
568+
assertThatThrownBy(() -> this.chatModel
569+
.stream(new Prompt(List.of(userMessage),
570+
OpenAiChatOptions.builder()
571+
.model(modelName)
572+
.outputAudio(new AudioParameters(Voice.ALLOY, AudioResponseFormat.WAV))
573+
.build()))
574+
.collectList()
575+
.block()).isInstanceOf(IllegalArgumentException.class)
567576
.hasMessageContaining("Audio parameters are not supported for streaming requests.");
568577
}
569578

0 commit comments

Comments
 (0)