Skip to content

fix: Incorrect outputModalities judgment in stream mode #3469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ public Flux<ChatResponse> internalStream(Prompt prompt, ChatResponse previousCha
return Flux.deferContextual(contextView -> {
ChatCompletionRequest request = createRequest(prompt, true);

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

if (request.audioParameters() != null) {
logger.warn("Audio parameters are not supported for streaming requests. Removing audio parameters.");
throw new IllegalArgumentException("Audio parameters are not supported for streaming requests.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ void multiModalityOutputAudio(String modelName) throws IOException {

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

assertThatThrownBy(() -> this.chatModel
Expand All @@ -564,6 +563,16 @@ void streamingMultiModalityOutputAudio(String modelName) throws IOException {
.build()))
.collectList()
.block()).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Audio output is not supported for streaming requests.");

assertThatThrownBy(() -> this.chatModel
.stream(new Prompt(List.of(userMessage),
OpenAiChatOptions.builder()
.model(modelName)
.outputAudio(new AudioParameters(Voice.ALLOY, AudioResponseFormat.WAV))
.build()))
.collectList()
.block()).isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Audio parameters are not supported for streaming requests.");
}

Expand Down