Skip to content

Commit 0e27181

Browse files
change guardrail field name (opensearch-project#2571) (opensearch-project#2574)
Signed-off-by: Jing Zhang <jngz@amazon.com> (cherry picked from commit fbb5ca7) Co-authored-by: Jing Zhang <jngz@amazon.com>
1 parent 22bd82a commit 0e27181

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

common/src/main/java/org/opensearch/ml/common/model/ModelGuardrail.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.opensearch.ml.common.transport.MLTaskResponse;
2929
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskAction;
3030
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskRequest;
31-
import org.opensearch.ml.common.utils.StringUtils;
3231

3332
import java.io.IOException;
3433
import java.security.AccessController;
@@ -51,7 +50,7 @@
5150
public class ModelGuardrail extends Guardrail {
5251
public static final String MODEL_ID_FIELD = "model_id";
5352
public static final String RESPONSE_FILTER_FIELD = "response_filter";
54-
public static final String RESPONSE_ACCEPT_FIELD = "response_accept";
53+
public static final String RESPONSE_VALIDATION_REGEX_FIELD = "response_validation_regex";
5554

5655
private String modelId;
5756
private String responseFilter;
@@ -67,7 +66,7 @@ public ModelGuardrail(String modelId, String responseFilter, String responseAcce
6766
this.responseAccept = responseAccept;
6867
}
6968
public ModelGuardrail(@NonNull Map<String, Object> params) {
70-
this((String) params.get(MODEL_ID_FIELD), (String) params.get(RESPONSE_FILTER_FIELD), (String) params.get(RESPONSE_ACCEPT_FIELD));
69+
this((String) params.get(MODEL_ID_FIELD), (String) params.get(RESPONSE_FILTER_FIELD), (String) params.get(RESPONSE_VALIDATION_REGEX_FIELD));
7170
}
7271

7372
public ModelGuardrail(StreamInput input) throws IOException {
@@ -157,7 +156,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
157156
builder.field(RESPONSE_FILTER_FIELD, responseFilter);
158157
}
159158
if (responseAccept != null) {
160-
builder.field(RESPONSE_ACCEPT_FIELD, responseAccept);
159+
builder.field(RESPONSE_VALIDATION_REGEX_FIELD, responseAccept);
161160
}
162161
builder.endObject();
163162
return builder;
@@ -180,7 +179,7 @@ public static ModelGuardrail parse(XContentParser parser) throws IOException {
180179
case RESPONSE_FILTER_FIELD:
181180
responseFilter = parser.text();
182181
break;
183-
case RESPONSE_ACCEPT_FIELD:
182+
case RESPONSE_VALIDATION_REGEX_FIELD:
184183
responseAccept = parser.text();
185184
break;
186185
default:

common/src/test/java/org/opensearch/ml/common/model/ModelGuardrailTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public void toXContent() throws IOException {
8383
modelGuardrail.toXContent(builder, ToXContent.EMPTY_PARAMS);
8484
String content = TestHelper.xContentBuilderToString(builder);
8585

86-
Assert.assertEquals("{\"model_id\":\"test_model_id\",\"response_filter\":\"$.test\",\"response_accept\":\"^accept$\"}", content);
86+
Assert.assertEquals("{\"model_id\":\"test_model_id\",\"response_filter\":\"$.test\",\"response_validation_regex\":\"^accept$\"}", content);
8787
}
8888

8989
@Test
9090
public void parse() throws IOException {
91-
String jsonStr = "{\"model_id\":\"test_model_id\",\"response_filter\":\"$.test\",\"response_accept\":\"^accept$\"}";
91+
String jsonStr = "{\"model_id\":\"test_model_id\",\"response_filter\":\"$.test\",\"response_validation_regex\":\"^accept$\"}";
9292
XContentParser parser = XContentType.JSON.xContent().createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY,
9393
Collections.emptyList()).getNamedXContents()), null, jsonStr);
9494
parser.nextToken();

plugin/src/test/java/org/opensearch/ml/rest/RestMLGuardrailsIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ protected Response registerRemoteModelWithModelGuardrails(String name, String co
467467
+ " \"model_id\": \""
468468
+ guardrailModelId
469469
+ "\",\n"
470-
+ " \"response_accept\": \"^\\\"\\\\s*[Aa]ccept\\\\s*\\\"$\""
470+
+ " \"response_validation_regex\": \"^\\\"\\\\s*[Aa]ccept\\\\s*\\\"$\""
471471
+ " },\n"
472472
+ " \"output_guardrail\": {\n"
473473
+ " \"model_id\": \""
474474
+ guardrailModelId
475475
+ "\",\n"
476-
+ " \"response_accept\": \"^\\\"\\\\s*[Aa]ccept\\\\s*\\\"$\""
476+
+ " \"response_validation_regex\": \"^\\\"\\\\s*[Aa]ccept\\\\s*\\\"$\""
477477
+ " }\n"
478478
+ " }\n"
479479
+ "}";

0 commit comments

Comments
 (0)