Skip to content

Commit

Permalink
CreateAnomalyDetectorTool supports empty model_type (#457) (#463)
Browse files Browse the repository at this point in the history
* CreateAnomalyDetectorTool supports empty model_type



* Optimize code



* Add some comment



---------


(cherry picked from commit cfc88d8)

Signed-off-by: gaobinlong <gbinlong@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: zane-neo <zaniu@amazon.com>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent de9d588 commit 8a57a6a
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 8a57a6a

Please sign in to comment.