Skip to content

Commit ad3c4e4

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

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public Flux<ChatResponse> internalStream(Prompt prompt, ChatResponse previousCha
272272
ChatCompletionRequest request = createRequest(prompt, true);
273273

274274
if (request.outputModalities() != null) {
275-
if (request.outputModalities().stream().anyMatch(m -> m.equals("audio"))) {
275+
if (request.outputModalities().stream().anyMatch(OpenAiApi.OutputModality.AUDIO::equals)) {
276276
logger.warn("Audio output is not supported for streaming requests. Removing audio output.");
277277
throw new IllegalArgumentException("Audio output is not supported for streaming requests.");
278278
}

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)