Skip to content

Commit

Permalink
fix parameter parsing bug for create connector input (#1185)
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <[email protected]>
  • Loading branch information
ylwu-amzn authored Aug 4, 2023
1 parent c94eaa8 commit eb1a72f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;

import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
import static org.opensearch.ml.common.utils.StringUtils.getParameterMap;

@Data
public class MLCreateConnectorInput implements ToXContentObject, Writeable {
Expand Down Expand Up @@ -125,7 +126,7 @@ public static MLCreateConnectorInput parse(XContentParser parser) throws IOExcep
protocol = parser.text();
break;
case CONNECTOR_PARAMETERS_FIELD:
parameters = parser.mapStrings();
parameters = getParameterMap(parser.map());
break;
case CONNECTOR_CREDENTIAL_FIELD:
credential = parser.mapStrings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ public void testParse() throws Exception {
});
}

@Test
public void testParse_ArrayParameter() throws Exception {
String expectedInputStr = "{\"name\":\"test_connector_name\"," +
"\"description\":\"this is a test connector\",\"version\":\"1\",\"protocol\":\"http\"," +
"\"parameters\":{\"input\":[\"test input value\"]},\"credential\":{\"key\":\"test_key_value\"}," +
"\"actions\":[{\"action_type\":\"PREDICT\",\"method\":\"POST\",\"url\":\"https://test.com\"," +
"\"headers\":{\"api_key\":\"${credential.key}\"}," +
"\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\"," +
"\"pre_process_function\":\"connector.pre_process.openai.embedding\"," +
"\"post_process_function\":\"connector.post_process.openai.embedding\"}]," +
"\"backend_roles\":[\"role1\",\"role2\"],\"add_all_backend_roles\":false," +
"\"access_mode\":\"PUBLIC\"}";
testParseFromJsonString(expectedInputStr, parsedInput -> {
assertEquals("test_connector_name", parsedInput.getName());
assertEquals(1, parsedInput.getParameters().size());
assertEquals("[\"test input value\"]", parsedInput.getParameters().get("input"));
});
}

@Test
public void testParseWithDryRun() throws Exception {
String expectedInputStrWithDryRun = "{\"dry_run\":true}";
Expand Down

0 comments on commit eb1a72f

Please sign in to comment.