Fix an issue related to the Azure OpenAI streamig response

This issue in the Flux streaming logic was causing chunks
  to be aggreagated in a single response.

  Re-enable the AzureOpenAiAutoConfigurationIT
This commit is contained in:
Christian Tzolov
2024-05-27 00:51:36 +02:00
parent dc656ce3bc
commit 178a607cf6
4 changed files with 25 additions and 5 deletions

View File

@@ -183,8 +183,8 @@ public class AzureOpenAiChatModel
isFunctionCall.set(false);
return true;
}
return false;
}, false)
return !isFunctionCall.get();
})
.concatMapIterable(window -> {
final var reduce = window.reduce(MergeUtils.emptyChatCompletions(), MergeUtils::mergeChatCompletions);
return List.of(reduce);

View File

@@ -80,6 +80,29 @@ class OpenAiChatModelIT extends AbstractIT {
// needs fine tuning... evaluateQuestionAndAnswer(request, response, false);
}
@Test
void streamRoleTest() {
UserMessage userMessage = new UserMessage(
"Tell me about 3 famous pirates from the Golden Age of Piracy and what they did.");
SystemPromptTemplate systemPromptTemplate = new SystemPromptTemplate(systemResource);
Message systemMessage = systemPromptTemplate.createMessage(Map.of("name", "Bob", "voice", "pirate"));
Prompt prompt = new Prompt(List.of(userMessage, systemMessage));
Flux<ChatResponse> flux = streamingChatModel.stream(prompt);
List<ChatResponse> responses = flux.collectList().block();
assertThat(responses.size()).isGreaterThan(1);
String stitchedResponseContent = responses.stream()
.map(ChatResponse::getResults)
.flatMap(List::stream)
.map(Generation::getOutput)
.map(AssistantMessage::getContent)
.collect(Collectors.joining());
assertThat(stitchedResponseContent).contains("Blackbeard");
}
@Test
void listOutputConverter() {
DefaultConversionService conversionService = new DefaultConversionService();