|
20 | 20 | import org.opensearch.flowframework.workflow.ProcessNode;
|
21 | 21 | import org.opensearch.flowframework.workflow.WorkflowData;
|
22 | 22 | import org.opensearch.flowframework.workflow.WorkflowStep;
|
| 23 | +import org.opensearch.ml.common.model.Guardrails; |
23 | 24 |
|
24 | 25 | import java.io.IOException;
|
25 | 26 | import java.util.ArrayList;
|
|
32 | 33 | import static java.util.concurrent.TimeUnit.SECONDS;
|
33 | 34 | import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
|
34 | 35 | import static org.opensearch.flowframework.common.CommonValue.CONFIGURATIONS;
|
| 36 | +import static org.opensearch.flowframework.common.CommonValue.GUARDRAILS_FIELD; |
35 | 37 | import static org.opensearch.flowframework.common.CommonValue.TOOLS_ORDER_FIELD;
|
36 | 38 | import static org.opensearch.flowframework.util.ParseUtils.buildStringToObjectMap;
|
37 | 39 | import static org.opensearch.flowframework.util.ParseUtils.buildStringToStringMap;
|
@@ -95,6 +97,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
|
95 | 97 | xContentBuilder.field(e.getKey());
|
96 | 98 | if (e.getValue() instanceof String || e.getValue() instanceof Number || e.getValue() instanceof Boolean) {
|
97 | 99 | xContentBuilder.value(e.getValue());
|
| 100 | + } else if (GUARDRAILS_FIELD.equals(e.getKey())) { |
| 101 | + Guardrails g = (Guardrails) e.getValue(); |
| 102 | + xContentBuilder.value(g); |
98 | 103 | } else if (e.getValue() instanceof Map<?, ?>) {
|
99 | 104 | buildStringToStringMap(xContentBuilder, (Map<?, ?>) e.getValue());
|
100 | 105 | } else if (e.getValue() instanceof Object[]) {
|
@@ -156,13 +161,16 @@ public static WorkflowNode parse(XContentParser parser) throws IOException {
|
156 | 161 | userInputs.put(inputFieldName, parser.text());
|
157 | 162 | break;
|
158 | 163 | case START_OBJECT:
|
159 |
| - if (CONFIGURATIONS.equals(inputFieldName)) { |
| 164 | + if (GUARDRAILS_FIELD.equals(inputFieldName)) { |
| 165 | + userInputs.put(inputFieldName, Guardrails.parse(parser)); |
| 166 | + break; |
| 167 | + } else if (CONFIGURATIONS.equals(inputFieldName)) { |
160 | 168 | Map<String, Object> configurationsMap = parser.map();
|
161 | 169 | try {
|
162 | 170 | String configurationsString = ParseUtils.parseArbitraryStringToObjectMapToString(configurationsMap);
|
163 | 171 | userInputs.put(inputFieldName, configurationsString);
|
164 | 172 | } catch (Exception ex) {
|
165 |
| - String errorMessage = "Failed to parse configuration map"; |
| 173 | + String errorMessage = "Failed to parse" + inputFieldName + "map"; |
166 | 174 | logger.error(errorMessage, ex);
|
167 | 175 | throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST);
|
168 | 176 | }
|
|
0 commit comments