Skip to content

Commit

Permalink
[ML] Fixing streaming tests locale issue (#118481) (#118809)
Browse files Browse the repository at this point in the history
* Fixing the string locale

* Missing a toUpper

(cherry picked from commit 5572777)

# Conflicts:
#	muted-tests.yml
  • Loading branch information
jonathan-buttner authored Dec 17, 2024
1 parent 49b18e2 commit 6ed0d26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ public static String randomAlphaOfLength(int codeUnits) {

/**
* Generate a random string containing only alphanumeric characters.
* <b>The locale for the string is {@link Locale#ROOT}.</b>
* @param length the length of the string to generate
* @return the generated string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -317,7 +318,7 @@ public void testSupportedStream() throws Exception {
var events = streamInferOnMockService(modelId, TaskType.COMPLETION, input);

var expectedResponses = Stream.concat(
input.stream().map(String::toUpperCase).map(str -> "{\"completion\":[{\"delta\":\"" + str + "\"}]}"),
input.stream().map(s -> s.toUpperCase(Locale.ROOT)).map(str -> "{\"completion\":[{\"delta\":\"" + str + "\"}]}"),
Stream.of("[DONE]")
).iterator();
assertThat(events.size(), equalTo((input.size() + 1) * 2));
Expand Down Expand Up @@ -356,7 +357,9 @@ public void testUnifiedCompletionInference() throws Exception {
}

private static Iterator<String> expectedResultsIterator(List<String> input) {
return Stream.concat(input.stream().map(String::toUpperCase).map(InferenceCrudIT::expectedResult), Stream.of("[DONE]")).iterator();
// The Locale needs to be ROOT to match what the test service is going to respond with
return Stream.concat(input.stream().map(s -> s.toUpperCase(Locale.ROOT)).map(InferenceCrudIT::expectedResult), Stream.of("[DONE]"))
.iterator();
}

private static String expectedResult(String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Flow;
Expand Down Expand Up @@ -142,7 +143,7 @@ public void unifiedCompletionInfer(
}

private StreamingChatCompletionResults makeResults(List<String> input) {
var responseIter = input.stream().map(String::toUpperCase).iterator();
var responseIter = input.stream().map(s -> s.toUpperCase(Locale.ROOT)).iterator();
return new StreamingChatCompletionResults(subscriber -> {
subscriber.onSubscribe(new Flow.Subscription() {
@Override
Expand Down Expand Up @@ -173,7 +174,7 @@ private ChunkedToXContent completionChunk(String delta) {
}

private StreamingUnifiedChatCompletionResults makeUnifiedResults(UnifiedCompletionRequest request) {
var responseIter = request.messages().stream().map(message -> message.content().toString().toUpperCase()).iterator();
var responseIter = request.messages().stream().map(message -> message.content().toString().toUpperCase(Locale.ROOT)).iterator();
return new StreamingUnifiedChatCompletionResults(subscriber -> {
subscriber.onSubscribe(new Flow.Subscription() {
@Override
Expand Down

0 comments on commit 6ed0d26

Please sign in to comment.