Skip to content

Commit

Permalink
Add UT for both embedding and remote cases for all remote embedding s…
Browse files Browse the repository at this point in the history
…chema

Signed-off-by: b4sjoo <[email protected]>
  • Loading branch information
b4sjoo committed Dec 20, 2024
1 parent 1f91102 commit 9ff2d5d
Showing 1 changed file with 119 additions and 1 deletion.
120 changes: 119 additions & 1 deletion plugin/src/test/java/org/opensearch/ml/utils/MLNodeUtilsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testValidateSchema() throws IOException {
}

@Test
public void testValidateEmbeddingInputWithRemoteSchema() throws IOException {
public void testValidateEmbeddingInputWithGeneralEmbeddingRemoteSchema() throws IOException {
String schema = "{\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
Expand All @@ -91,6 +91,124 @@ public void testValidateEmbeddingInputWithRemoteSchema() throws IOException {
MLNodeUtils.validateSchema(schema, json);
}

@Test
public void testValidateRemoteInputWithGeneralEmbeddingRemoteSchema() throws IOException {
String schema = "{\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"parameters\": {\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"texts\": {\n"
+ " \"type\": \"array\",\n"
+ " \"items\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " \"required\": [\n"
+ " \"texts\"\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}";
String json = "{\"parameters\": {\"texts\": [\"Hello\",\"world\"]}}";
MLNodeUtils.validateSchema(schema, json);
}

@Test
public void testValidateEmbeddingInputWithTitanTextRemoteSchema() throws IOException {
String schema = "{\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"parameters\": {\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"inputText\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " },\n"
+ " \"required\": [\n"
+ " \"inputText\"\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}";
String json = "{\"text_docs\":[ \"today is sunny\", \"today is sunny\"]}";
MLNodeUtils.validateSchema(schema, json);
}

@Test
public void testValidateRemoteInputWithTitanTextRemoteSchema() throws IOException {
String schema = "{\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"parameters\": {\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"inputText\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " },\n"
+ " \"required\": [\n"
+ " \"inputText\"\n"
+ " ]\n"
+ " }\n"
+ " }\n"
+ "}";
String json = "{\"parameters\": {\"inputText\": \"Say this is a test\"}}";
MLNodeUtils.validateSchema(schema, json);
}

@Test
public void testValidateEmbeddingInputWithTitanImageRemoteSchema() throws IOException {
String schema = "{\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"parameters\": {\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"inputText\": {\n"
+ " \"type\": \"string\"\n"
+ " },\n"
+ " \"inputImage\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
String json = "{\"text_docs\":[ \"today is sunny\", \"today is sunny\"]}";
MLNodeUtils.validateSchema(schema, json);
}

@Test
public void testValidateRemoteInputWithTitanImageRemoteSchema() throws IOException {
String schema = "{\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"parameters\": {\n"
+ " \"type\": \"object\",\n"
+ " \"properties\": {\n"
+ " \"inputText\": {\n"
+ " \"type\": \"string\"\n"
+ " },\n"
+ " \"inputImage\": {\n"
+ " \"type\": \"string\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";
String json = "{{\n"
+ " \"parameters\": {\n"
+ " \"inputText\": \"Say this is a test\",\n"
+ " \"inputImage\": \"/9jk=\"\n"
+ " }\n"
+ "}";
MLNodeUtils.validateSchema(schema, json);
}

@Test
public void testProcessRemoteInferenceInputDataSetParametersValueNoParameters() throws IOException {
String json = "{\"key1\":\"foo\",\"key2\":123,\"key3\":true}";
Expand Down

0 comments on commit 9ff2d5d

Please sign in to comment.