Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parameter parsing bug for create connector input #1185

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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