Skip to content
Closed
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
@@ -1,5 +1,5 @@
/*
* Copyright 2023 - 2024 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,10 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
Expand Down Expand Up @@ -81,6 +84,29 @@ void roleTest() {
// needs fine tuning... evaluateQuestionAndAnswer(request, response, false);
}

@Test
void streamCompletenessTest() throws InterruptedException {
UserMessage userMessage = new UserMessage(
"List ALL natural numbers in range [1, 1000]. Make sure to not omit any.");
Prompt prompt = new Prompt(List.of(userMessage));

StringBuilder answer = new StringBuilder();
CountDownLatch latch = new CountDownLatch(1);

Flux<ChatResponse> chatResponseFlux = streamingChatModel.stream(prompt).doOnNext(chatResponse -> {
String responseContent = chatResponse.getResults().get(0).getOutput().getContent();
answer.append(responseContent);
}).doOnComplete(() -> {
logger.info(answer.toString());
latch.countDown();
});
chatResponseFlux.subscribe();
assertThat(latch.await(120, TimeUnit.SECONDS)).isTrue();
IntStream.rangeClosed(1, 1000).forEach(n -> {
assertThat(answer).contains(String.valueOf(n));
});
}

@Test
void streamRoleTest() {
UserMessage userMessage = new UserMessage(
Expand Down