Skip to content

Commit

Permalink
Address Naveen's comment
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Aug 21, 2024
1 parent 7799975 commit 4c93548
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.stream.Collectors;

import org.opensearch.core.action.ActionListener;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.util.CollectionUtils;
import org.opensearch.ml.client.MachineLearningNodeClient;
import org.opensearch.ml.common.FunctionName;
Expand Down Expand Up @@ -236,7 +237,7 @@ private List<List<Float>> buildVectorFromResponse(MLOutput mlOutput) {
final List<ModelTensor> tensorsList = tensors.getMlModelTensors();
for (final ModelTensor tensor : tensorsList) {
if (Objects.isNull(tensor.getData())) {
if (Objects.nonNull(tensor.getDataAsMap()) && checkIfStringIsNotBlank((String) tensor.getDataAsMap().get("message"))) {
if (Objects.nonNull(tensor.getDataAsMap()) && Strings.hasText((String) tensor.getDataAsMap().get("message"))) {
String errorFromModel = (String) tensor.getDataAsMap().get("message");
throw new IllegalStateException(
String.format(Locale.ROOT, "%s: %s", EXCEPTION_MESSAGE_PREFIX_MODEL_PREDICT_FAILED, errorFromModel)
Expand Down Expand Up @@ -310,18 +311,4 @@ private MLInput createMLMultimodalInput(final List<String> targetResponseFilters
final MLInputDataset inputDataset = new TextDocsInputDataSet(inputText, modelResultFilter);
return new MLInput(FunctionName.TEXT_EMBEDDING, null, inputDataset);
}

private boolean checkIfStringIsNotBlank(String value) {
if (value == null || value.isEmpty()) {
return false;
}
// returns true when the String even contain a single character which is not a white space.
for (int i = 0; i < value.length(); ++i) {
char c = value.charAt(i);
if (!Character.isWhitespace(c)) {
return true;
}
}
return false;
}
}

0 comments on commit 4c93548

Please sign in to comment.