Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/main/java/org/opensearch/agent/tools/PPLTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.opensearch.agent.tools.utils.CommonConstants.COMMON_MODEL_ID_FIELD;
import static org.opensearch.ml.common.CommonValue.TENANT_ID_FIELD;
import static org.opensearch.ml.common.CommonValue.TOOL_INPUT_SCHEMA_FIELD;
import static org.opensearch.ml.common.utils.ToolUtils.NO_ESCAPE_PARAMS;

import java.io.IOException;
Expand Down Expand Up @@ -87,7 +88,25 @@ public class PPLTool implements WithModelTool {
private Client client;

private static final String DEFAULT_DESCRIPTION =
"\"Use this tool when user ask question based on the data in the cluster or parse user statement about which index to use in a conversion.\nAlso use this tool when question only contains index information.\n1. If uesr question contain both question and index name, the input parameters are {'question': UserQuestion, 'index': IndexName}.\n2. If user question contain only question, the input parameter is {'question': UserQuestion}.\n3. If uesr question contain only index name, find the original human input from the conversation histroy and formulate parameter as {'question': UserQuestion, 'index': IndexName}\nThe index name should be exactly as stated in user's input.";
"Use this tool to answer user questions about data in the cluster by generating a PPL query.";

public static final String DEFAULT_INPUT_SCHEMA = """
{
"type": "object",
"properties": {
"question": {
"type": "string",
"description": "The natural language question to generate PPL query for"
},
"index": {
"type": "string",
"description": "The index name to query against"
}
},
"required": ["question", "index"],
"additionalProperties": false
}
""";

private static final String TABLE_INFO_KEY = "table_info";
private static final String MAPPING_KEY = "mappings";
Expand Down Expand Up @@ -116,6 +135,9 @@ public class PPLTool implements WithModelTool {

private static Gson gson = org.opensearch.ml.common.utils.StringUtils.gson;

public static final Map<String, Object> DEFAULT_ATTRIBUTES = Map
.of(TOOL_INPUT_SCHEMA_FIELD, gson.toJson(gson.fromJson(DEFAULT_INPUT_SCHEMA, Map.class)));

private static Map<String, String> DEFAULT_PROMPT_DICT;

private static Set<String> ALLOWED_FIELDS_TYPE;
Expand Down Expand Up @@ -203,6 +225,7 @@ public PPLTool(
this.previousToolKey = previousToolKey;
this.head = head;
this.execute = execute;
this.attributes = new HashMap<>(DEFAULT_ATTRIBUTES);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -448,6 +471,11 @@ public String getDefaultVersion() {
return null;
}

@Override
public Map<String, Object> getDefaultAttributes() {
return DEFAULT_ATTRIBUTES;
}

@Override
public List<String> getAllModelKeys() {
return List.of(COMMON_MODEL_ID_FIELD);
Expand Down
Loading