Skip to content

Commit

Permalink
fix text docs input unescaped error; enable deploy remote model (#1407)…
Browse files Browse the repository at this point in the history
… (#1408)

Signed-off-by: Yaliang Wu <[email protected]>
(cherry picked from commit 6e0d949)

Co-authored-by: Yaliang Wu <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and ylwu-amzn committed Oct 4, 2023
1 parent 9acb60d commit 7e7afea
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,24 @@ public static RemoteInferenceInputDataSet processInput(MLInput mlInput, Connecto
return inputData;
}
private static RemoteInferenceInputDataSet processTextDocsInput(TextDocsInputDataSet inputDataSet, Connector connector, Map<String, String> parameters, ScriptService scriptService) {
List<String> docs = new ArrayList<>(inputDataSet.getDocs());
Optional<ConnectorAction> predictAction = connector.findPredictAction();
if (predictAction.isEmpty()) {
throw new IllegalArgumentException("no predict action found");
}
String preProcessFunction = predictAction.get().getPreProcessFunction();
preProcessFunction = preProcessFunction == null ? MLPreProcessFunction.TEXT_DOCS_TO_DEFAULT_EMBEDDING_INPUT : preProcessFunction;
if (MLPreProcessFunction.contains(preProcessFunction)) {
Map<String, Object> buildInFunctionResult = MLPreProcessFunction.get(preProcessFunction).apply(docs);
Map<String, Object> buildInFunctionResult = MLPreProcessFunction.get(preProcessFunction).apply(inputDataSet.getDocs());
return RemoteInferenceInputDataSet.builder().parameters(convertScriptStringToJsonString(buildInFunctionResult)).build();
} else {
List<String> docs = new ArrayList<>();
for (String doc : inputDataSet.getDocs()) {
if (doc != null) {
docs.add(gson.toJson(doc));
} else {
docs.add(null);
}
}
if (preProcessFunction.contains("${parameters")) {
StringSubstitutor substitutor = new StringSubstitutor(parameters, "${parameters.", "}");
preProcessFunction = substitutor.replace(preProcessFunction);
Expand Down

0 comments on commit 7e7afea

Please sign in to comment.