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

Revert Text Block changes from "Enhance validation for create connector API" #3260 #3329

Merged
merged 1 commit into from
Jan 3, 2025
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 @@ -100,11 +100,11 @@ public void toXContent_NullValue() throws IOException {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
String content = TestHelper.xContentBuilderToString(builder);
String expctedContent = """
{"action_type":"PREDICT","method":"http","url":"https://test.com",\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}"}\
""";
assertEquals(expctedContent, content);
assertEquals(
"{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
+ "\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\"}",
content
);
}

@Test
Expand All @@ -127,23 +127,21 @@ public void toXContent() throws IOException {
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
String content = TestHelper.xContentBuilderToString(builder);
String expctedContent = """
{"action_type":"PREDICT","method":"http","url":"https://test.com","headers":{"key1":"value1"},\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
"pre_process_function":"connector.pre_process.openai.embedding",\
"post_process_function":"connector.post_process.openai.embedding"}\
""";
assertEquals(expctedContent, content);
assertEquals(
"{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
+ "\"headers\":{\"key1\":\"value1\"},\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}",
content
);
}

@Test
public void parse() throws IOException {
String jsonStr = """
{"action_type":"PREDICT","method":"http","url":"https://test.com","headers":{"key1":"value1"},\
"request_body":"{\\"input\\": \\"${parameters.input}\\"}",\
"pre_process_function":"connector.pre_process.openai.embedding",\
"post_process_function":"connector.post_process.openai.embedding"}"\
""";
String jsonStr = "{\"action_type\":\"PREDICT\",\"method\":\"http\",\"url\":\"https://test.com\","
+ "\"headers\":{\"key1\":\"value1\"},\"request_body\":\"{\\\"input\\\": \\\"${parameters.input}\\\"}\","
+ "\"pre_process_function\":\"connector.pre_process.openai.embedding\","
+ "\"post_process_function\":\"connector.post_process.openai.embedding\"}";
XContentParser parser = XContentType.JSON
.xContent()
.createParser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,18 @@ public class MLCreateConnectorInputTests {
private static final String TEST_CREDENTIAL_VALUE = "test_key_value";
private static final String TEST_ROLE1 = "role1";
private static final String TEST_ROLE2 = "role2";
private final 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","client_config":{"max_connection":20,\
"connection_timeout":10000,"read_timeout":10000,\
"retry_backoff_millis":10,"retry_timeout_seconds":10,"max_retry_times":-1,"retry_backoff_policy":"constant"}}\
""";
private final 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\",\"client_config\":{\"max_connection\":20,"
+ "\"connection_timeout\":10000,\"read_timeout\":10000,"
+ "\"retry_backoff_millis\":10,\"retry_timeout_seconds\":10,\"max_retry_times\":-1,\"retry_backoff_policy\":\"constant\"}}";

@Before
public void setUp() {
Expand Down Expand Up @@ -238,15 +237,16 @@ 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"};\
""";
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());
Expand Down
Loading