|
18 | 18 | import java.util.*;
|
19 | 19 | import java.util.function.Function;
|
20 | 20 |
|
| 21 | +import org.json.JSONException; |
21 | 22 | import org.json.JSONObject;
|
22 | 23 | import org.json.JSONArray;
|
23 | 24 | import org.apache.commons.lang3.StringUtils;
|
24 | 25 | import org.apache.commons.text.StringSubstitutor;
|
25 | 26 | import org.opensearch.OpenSearchParseException;
|
26 | 27 | import org.opensearch.OpenSearchStatusException;
|
| 28 | +import org.opensearch.common.xcontent.XContentFactory; |
| 29 | +import org.opensearch.core.xcontent.ToXContent; |
27 | 30 | import org.opensearch.core.xcontent.XContent;
|
28 | 31 | import org.opensearch.core.xcontent.XContentBuilder;
|
29 | 32 | import org.opensearch.ml.common.connector.Connector;
|
@@ -265,6 +268,16 @@ public static SdkHttpFullRequest signRequest(
|
265 | 268 | return signer.sign(request, params);
|
266 | 269 | }
|
267 | 270 |
|
| 271 | + public static JSONObject parametersObjectExtractor(MLInput mlInput) throws IOException { |
| 272 | + XContentBuilder mlInputXContent = mlInput.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS); |
| 273 | + try { |
| 274 | + JSONObject mlInputObject = new JSONObject(mlInputXContent.toString()); |
| 275 | + return (JSONObject) mlInputObject.get("parameters"); |
| 276 | + } catch (JSONException e) { |
| 277 | + throw new OpenSearchParseException("Failed to extract parameters object from MLInput", e.getMessage()); |
| 278 | + } |
| 279 | + } |
| 280 | + |
268 | 281 | public static void validateSchema(String schemaString, String instanceString) {
|
269 | 282 | try {
|
270 | 283 | // parse the schema JSON as string
|
|
0 commit comments