Skip to content
3 changes: 3 additions & 0 deletions src/main/java/org/opensearch/agent/ToolPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.opensearch.agent.tools.CreateAlertTool;
import org.opensearch.agent.tools.CreateAnomalyDetectorTool;
import org.opensearch.agent.tools.CreateAnomalyDetectorToolEnhanced;
import org.opensearch.agent.tools.DataDistributionTool;
import org.opensearch.agent.tools.LogPatternAnalysisTool;
import org.opensearch.agent.tools.LogPatternTool;
Expand Down Expand Up @@ -100,6 +101,7 @@ public Collection<Object> createComponents(
SearchMonitorsTool.Factory.getInstance().init(client);
CreateAlertTool.Factory.getInstance().init(client);
CreateAnomalyDetectorTool.Factory.getInstance().init(client);
CreateAnomalyDetectorToolEnhanced.Factory.getInstance().init(client, namedWriteableRegistry);
LogPatternTool.Factory.getInstance().init(client, xContentRegistry);
WebSearchTool.Factory.getInstance().init(threadPool);
LogPatternAnalysisTool.Factory.getInstance().init(client);
Expand All @@ -123,6 +125,7 @@ public List<Tool.Factory<? extends Tool>> getToolFactories() {
SearchMonitorsTool.Factory.getInstance(),
CreateAlertTool.Factory.getInstance(),
CreateAnomalyDetectorTool.Factory.getInstance(),
CreateAnomalyDetectorToolEnhanced.Factory.getInstance(),
LogPatternTool.Factory.getInstance(),
WebSearchTool.Factory.getInstance(),
LogPatternAnalysisTool.Factory.getInstance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.security.PrivilegedExceptionAction;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -209,7 +208,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
ToolHelper.extractFieldNamesTypes(mappingSource, fieldsToType, "", true);

// find all date type fields from the mapping
final Set<String> dateFields = findDateTypeFields(fieldsToType);
final Set<String> dateFields = ToolHelper.findDateTypeFields(fieldsToType);
if (dateFields.isEmpty()) {
throw new IllegalArgumentException(
"The index " + indexName + " doesn't have date type fields, cannot create an anomaly detector for it."
Expand All @@ -228,6 +227,8 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)

// construct the prompt
String prompt = constructPrompt(filteredMapping, firstIndexName);
log.info("Using prompt for anomaly detector creation (simple): {}", prompt);

RemoteInferenceInputDataSet inputDataSet = RemoteInferenceInputDataSet
.builder()
.parameters(Collections.singletonMap("prompt", prompt))
Expand Down Expand Up @@ -335,21 +336,8 @@ private Map<String, String> enrichParameters(Map<String, String> parameters) {

/**
*
* @param fieldsToType the flattened field-> field type mapping
* @return a list containing all the date type fields
*/
private Set<String> findDateTypeFields(final Map<String, String> fieldsToType) {
Set<String> result = new HashSet<>();
for (Map.Entry<String, String> entry : fieldsToType.entrySet()) {
String value = entry.getValue();
if (value.equals("date") || value.equals("date_nanos")) {
result.add(entry.getKey());
}
}
return result;
}

@SuppressWarnings("unchecked")
**/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SuppressWarnings should be outside of comment block. This may cause CI compile failure.

private static Map<String, String> loadDefaultPromptFromFile() {
try (InputStream inputStream = CreateAnomalyDetectorTool.class.getResourceAsStream("CreateAnomalyDetectorDefaultPrompt.json")) {
if (inputStream != null) {
Expand Down
Loading
Loading