Skip to content

Commit

Permalink
Fix test with empty result
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Sep 26, 2023
1 parent 12c41ff commit 4c90ed2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
import java.util.stream.Collectors;

public class TextExpansionResultsTests extends InferenceResultsTestCase<TextExpansionResults> {

public static TextExpansionResults createRandomResults() {
int numTokens = randomIntBetween(0, 20);
return createRandomResults(0, 20);
}

public static TextExpansionResults createRandomResults(int min, int max) {
int numTokens = randomIntBetween(min, max);
List<TextExpansionResults.WeightedToken> tokenList = new ArrayList<>();
for (int i = 0; i < numTokens; i++) {
tokenList.add(new TextExpansionResults.WeightedToken(Integer.toString(i), (float) randomDoubleBetween(0.0, 5.0, false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public TestServiceModel parseConfigLenient(String modelId, TaskType taskType, Ma
@Override
public void infer(Model model, String input, Map<String, Object> taskSettings, ActionListener<InferenceResults> listener) {
switch (model.getTaskType()) {
case SPARSE_EMBEDDING -> listener.onResponse(TextExpansionResultsTests.createRandomResults());
case SPARSE_EMBEDDING -> listener.onResponse(TextExpansionResultsTests.createRandomResults(1, 10));
default -> listener.onFailure(
new ElasticsearchStatusException(
TaskType.unsupportedTaskTypeErrorMsg(model.getTaskType(), NAME),
Expand Down

0 comments on commit 4c90ed2

Please sign in to comment.