Skip to content

Commit

Permalink
add illegeal exception
Browse files Browse the repository at this point in the history
Signed-off-by: xinyual <xinyual@amazon.com>
  • Loading branch information
xinyual committed Dec 26, 2023
1 parent 29deb8c commit 9ecc0ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/org/opensearch/agent/tools/PPLTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import org.json.JSONObject;
import org.opensearch.action.ActionRequest;
Expand Down Expand Up @@ -93,6 +94,9 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
parameters = extractFromChatParameters(parameters);
String indexName = parameters.get("index");
String question = parameters.get("question");
if (StringUtils.isBlank(indexName) || StringUtils.isBlank(question)) {
throw new IllegalArgumentException("Parameter index and question can not be null or empty.");
}
SearchRequest searchRequest = buildSearchRequest(indexName);
GetMappingsRequest getMappingsRequest = buildGetMappingRequest(indexName);
client.admin().indices().getMappings(getMappingsRequest, ActionListener.<GetMappingsResponse>wrap(getMappingsResponse -> {
Expand Down Expand Up @@ -341,7 +345,7 @@ private String parseOutput(String llmOutput, String indexName) {
// Joining the string back together
ppl = String.join("|", lists);
} else {
ppl = llmOutput;
throw new IllegalArgumentException("The returned PPL: " + llmOutput + " has wrong format");
}
}
ppl = ppl.replace("`", "");
Expand Down

0 comments on commit 9ecc0ce

Please sign in to comment.