forked from opensearch-project/ml-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing hidden agent (opensearch-project#2204) (opensearch-proje…
…ct#2220) * implementing hidden agent Signed-off-by: Dhrubo Saha <[email protected]> * added more validation in agent input Signed-off-by: Dhrubo Saha <[email protected]> * updated branch coverage Signed-off-by: Dhrubo Saha <[email protected]> * adding more test Signed-off-by: Dhrubo Saha <[email protected]> * fixing test Signed-off-by: Dhrubo Saha <[email protected]> * adding filter in search agent action Signed-off-by: Dhrubo Saha <[email protected]> * addressing comments Signed-off-by: Dhrubo Saha <[email protected]> * addressing comments Signed-off-by: Dhrubo Saha <[email protected]> * add locale root Signed-off-by: Dhrubo Saha <[email protected]> * addressing comments + put restriction on deleting hidden agents Signed-off-by: Dhrubo Saha <[email protected]> * updating isHiddenAgentfield Signed-off-by: Dhrubo Saha <[email protected]> --------- Signed-off-by: Dhrubo Saha <[email protected]> (cherry picked from commit affb047) Co-authored-by: Dhrubo Saha <[email protected]>
- Loading branch information
1 parent
af539dc
commit a7d1ef0
Showing
26 changed files
with
912 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
common/src/main/java/org/opensearch/ml/common/MLAgentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common; | ||
|
||
import java.util.Locale; | ||
|
||
public enum MLAgentType { | ||
FLOW, | ||
CONVERSATIONAL, | ||
CONVERSATIONAL_FLOW; | ||
|
||
public static MLAgentType from(String value) { | ||
if (value == null) { | ||
throw new IllegalArgumentException("Agent type can't be null"); | ||
} | ||
try { | ||
return MLAgentType.valueOf(value.toUpperCase(Locale.ROOT)); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Wrong Agent type"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
common/src/test/java/org/opensearch/ml/common/MLAgentTypeTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import static org.junit.Assert.*; | ||
public class MLAgentTypeTests { | ||
|
||
@Rule | ||
public ExpectedException exceptionRule = ExpectedException.none(); | ||
@Test | ||
public void testFromWithValidTypes() { | ||
// Test all enum values to ensure they return correctly | ||
assertEquals(MLAgentType.FLOW, MLAgentType.from("FLOW")); | ||
assertEquals(MLAgentType.CONVERSATIONAL, MLAgentType.from("CONVERSATIONAL")); | ||
assertEquals(MLAgentType.CONVERSATIONAL_FLOW, MLAgentType.from("CONVERSATIONAL_FLOW")); | ||
} | ||
|
||
@Test | ||
public void testFromWithLowerCase() { | ||
// Test with lowercase input | ||
assertEquals(MLAgentType.FLOW, MLAgentType.from("flow")); | ||
assertEquals(MLAgentType.CONVERSATIONAL, MLAgentType.from("conversational")); | ||
assertEquals(MLAgentType.CONVERSATIONAL_FLOW, MLAgentType.from("conversational_flow")); | ||
} | ||
|
||
@Test | ||
public void testFromWithMixedCase() { | ||
// Test with mixed case input | ||
assertEquals(MLAgentType.FLOW, MLAgentType.from("Flow")); | ||
assertEquals(MLAgentType.CONVERSATIONAL, MLAgentType.from("Conversational")); | ||
assertEquals(MLAgentType.CONVERSATIONAL_FLOW, MLAgentType.from("Conversational_Flow")); | ||
} | ||
|
||
@Test | ||
public void testFromWithInvalidType() { | ||
// This should throw an IllegalArgumentException | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("Wrong Agent type"); | ||
MLAgentType.from("INVALID_TYPE"); | ||
} | ||
|
||
@Test | ||
public void testFromWithEmptyString() { | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("Wrong Agent type"); | ||
// This should also throw an IllegalArgumentException | ||
MLAgentType.from(""); | ||
} | ||
|
||
@Test | ||
public void testFromWithNull() { | ||
// This should also throw an IllegalArgumentException | ||
exceptionRule.expect(IllegalArgumentException.class); | ||
exceptionRule.expectMessage("Agent type can't be null"); | ||
MLAgentType.from(null); | ||
} | ||
} |
Oops, something went wrong.