Skip to content

Commit

Permalink
Merge branch 'main' into alertToolImprove
Browse files Browse the repository at this point in the history
  • Loading branch information
qianheng-aws authored Nov 19, 2024
2 parents bfe59b7 + cfc88d8 commit a1c34f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,11 @@ public CreateAnomalyDetectorTool create(Map<String, Object> map) {
throw new IllegalArgumentException("model_id cannot be empty.");
}
String modelType = (String) map.getOrDefault("model_type", ModelType.CLAUDE.toString());
if (!ModelType.OPENAI.toString().equalsIgnoreCase(modelType) && !ModelType.CLAUDE.toString().equalsIgnoreCase(modelType)) {
// if model type is empty, use the default value
if (modelType.isEmpty()) {
modelType = ModelType.CLAUDE.toString();
} else if (!ModelType.OPENAI.toString().equalsIgnoreCase(modelType)
&& !ModelType.CLAUDE.toString().equalsIgnoreCase(modelType)) {
throw new IllegalArgumentException("Unsupported model_type: " + modelType);
}
String prompt = (String) map.getOrDefault("prompt", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ public void testToolWithCustomPrompt() {
);
}

@Test
public void testToolWithEmptyModelType() {
CreateAnomalyDetectorTool tool = CreateAnomalyDetectorTool.Factory
.getInstance()
.create(ImmutableMap.of("model_id", "modelId", "model_type", ""));
assertEquals(CreateAnomalyDetectorTool.TYPE, tool.getName());
assertEquals("modelId", tool.getModelId());
assertEquals("CLAUDE", tool.getModelType().toString());

tool
.run(
ImmutableMap.of("index", mockedIndexName),
ActionListener.<String>wrap(response -> assertEquals(mockedResult, response), log::info)
);
}

private void createMappings() {
indexMappings = new HashMap<>();
indexMappings
Expand Down

0 comments on commit a1c34f2

Please sign in to comment.