Skip to content

Commit 9ff2d5d

Browse files
committed
Add UT for both embedding and remote cases for all remote embedding schema
Signed-off-by: b4sjoo <sicheng.song@outlook.com>
1 parent 1f91102 commit 9ff2d5d

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

plugin/src/test/java/org/opensearch/ml/utils/MLNodeUtilsTests.java

+119-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testValidateSchema() throws IOException {
6767
}
6868

6969
@Test
70-
public void testValidateEmbeddingInputWithRemoteSchema() throws IOException {
70+
public void testValidateEmbeddingInputWithGeneralEmbeddingRemoteSchema() throws IOException {
7171
String schema = "{\n"
7272
+ " \"type\": \"object\",\n"
7373
+ " \"properties\": {\n"
@@ -91,6 +91,124 @@ public void testValidateEmbeddingInputWithRemoteSchema() throws IOException {
9191
MLNodeUtils.validateSchema(schema, json);
9292
}
9393

94+
@Test
95+
public void testValidateRemoteInputWithGeneralEmbeddingRemoteSchema() throws IOException {
96+
String schema = "{\n"
97+
+ " \"type\": \"object\",\n"
98+
+ " \"properties\": {\n"
99+
+ " \"parameters\": {\n"
100+
+ " \"type\": \"object\",\n"
101+
+ " \"properties\": {\n"
102+
+ " \"texts\": {\n"
103+
+ " \"type\": \"array\",\n"
104+
+ " \"items\": {\n"
105+
+ " \"type\": \"string\"\n"
106+
+ " }\n"
107+
+ " }\n"
108+
+ " },\n"
109+
+ " \"required\": [\n"
110+
+ " \"texts\"\n"
111+
+ " ]\n"
112+
+ " }\n"
113+
+ " }\n"
114+
+ "}";
115+
String json = "{\"parameters\": {\"texts\": [\"Hello\",\"world\"]}}";
116+
MLNodeUtils.validateSchema(schema, json);
117+
}
118+
119+
@Test
120+
public void testValidateEmbeddingInputWithTitanTextRemoteSchema() throws IOException {
121+
String schema = "{\n"
122+
+ " \"type\": \"object\",\n"
123+
+ " \"properties\": {\n"
124+
+ " \"parameters\": {\n"
125+
+ " \"type\": \"object\",\n"
126+
+ " \"properties\": {\n"
127+
+ " \"inputText\": {\n"
128+
+ " \"type\": \"string\"\n"
129+
+ " }\n"
130+
+ " },\n"
131+
+ " \"required\": [\n"
132+
+ " \"inputText\"\n"
133+
+ " ]\n"
134+
+ " }\n"
135+
+ " }\n"
136+
+ "}";
137+
String json = "{\"text_docs\":[ \"today is sunny\", \"today is sunny\"]}";
138+
MLNodeUtils.validateSchema(schema, json);
139+
}
140+
141+
@Test
142+
public void testValidateRemoteInputWithTitanTextRemoteSchema() throws IOException {
143+
String schema = "{\n"
144+
+ " \"type\": \"object\",\n"
145+
+ " \"properties\": {\n"
146+
+ " \"parameters\": {\n"
147+
+ " \"type\": \"object\",\n"
148+
+ " \"properties\": {\n"
149+
+ " \"inputText\": {\n"
150+
+ " \"type\": \"string\"\n"
151+
+ " }\n"
152+
+ " },\n"
153+
+ " \"required\": [\n"
154+
+ " \"inputText\"\n"
155+
+ " ]\n"
156+
+ " }\n"
157+
+ " }\n"
158+
+ "}";
159+
String json = "{\"parameters\": {\"inputText\": \"Say this is a test\"}}";
160+
MLNodeUtils.validateSchema(schema, json);
161+
}
162+
163+
@Test
164+
public void testValidateEmbeddingInputWithTitanImageRemoteSchema() throws IOException {
165+
String schema = "{\n"
166+
+ " \"type\": \"object\",\n"
167+
+ " \"properties\": {\n"
168+
+ " \"parameters\": {\n"
169+
+ " \"type\": \"object\",\n"
170+
+ " \"properties\": {\n"
171+
+ " \"inputText\": {\n"
172+
+ " \"type\": \"string\"\n"
173+
+ " },\n"
174+
+ " \"inputImage\": {\n"
175+
+ " \"type\": \"string\"\n"
176+
+ " }\n"
177+
+ " }\n"
178+
+ " }\n"
179+
+ " }\n"
180+
+ "}";
181+
String json = "{\"text_docs\":[ \"today is sunny\", \"today is sunny\"]}";
182+
MLNodeUtils.validateSchema(schema, json);
183+
}
184+
185+
@Test
186+
public void testValidateRemoteInputWithTitanImageRemoteSchema() throws IOException {
187+
String schema = "{\n"
188+
+ " \"type\": \"object\",\n"
189+
+ " \"properties\": {\n"
190+
+ " \"parameters\": {\n"
191+
+ " \"type\": \"object\",\n"
192+
+ " \"properties\": {\n"
193+
+ " \"inputText\": {\n"
194+
+ " \"type\": \"string\"\n"
195+
+ " },\n"
196+
+ " \"inputImage\": {\n"
197+
+ " \"type\": \"string\"\n"
198+
+ " }\n"
199+
+ " }\n"
200+
+ " }\n"
201+
+ " }\n"
202+
+ "}";
203+
String json = "{{\n"
204+
+ " \"parameters\": {\n"
205+
+ " \"inputText\": \"Say this is a test\",\n"
206+
+ " \"inputImage\": \"/9jk=\"\n"
207+
+ " }\n"
208+
+ "}";
209+
MLNodeUtils.validateSchema(schema, json);
210+
}
211+
94212
@Test
95213
public void testProcessRemoteInferenceInputDataSetParametersValueNoParameters() throws IOException {
96214
String json = "{\"key1\":\"foo\",\"key2\":123,\"key3\":true}";

0 commit comments

Comments
 (0)