Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateAnomalyDetectorTool supports empty model_type #457

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
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()) {
zane-neo marked this conversation as resolved.
Show resolved Hide resolved
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
Loading