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

updating request field for the connectors #1215

Closed
wants to merge 0 commits into from

Conversation

dhrubo-os
Copy link
Collaborator

Description

[updating request field for the connectors]

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 18, 2023 00:00 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 18, 2023 00:00 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 18, 2023 00:17 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 18, 2023 00:17 — with GitHub Actions Failure
@dhrubo-os dhrubo-os had a problem deploying to ml-commons-cicd-env August 18, 2023 00:24 — with GitHub Actions Failure
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 00:24 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 00:24 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 00:45 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 00:45 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 00:45 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Merging #1215 (a48dba5) into 2.9 (1ffd6a5) will increase coverage by 0.04%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##                2.9    #1215      +/-   ##
============================================
+ Coverage     78.76%   78.81%   +0.04%     
- Complexity     2136     2138       +2     
============================================
  Files           168      168              
  Lines          8745     8745              
  Branches        877      877              
============================================
+ Hits           6888     6892       +4     
+ Misses         1456     1453       -3     
+ Partials        401      400       -1     
Flag Coverage Δ
ml-commons 78.81% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 01:39 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 01:39 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 01:39 — with GitHub Actions Inactive
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env August 18, 2023 01:39 — with GitHub Actions Inactive
protected String applyCustomSubstitution(Map<String, String> parameters, String inputPayload) {

if (parameters == null) {
throw new IllegalArgumentException("Some parameter placeholder not filled in payload: input");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add limitation that parameters can't be null. If inputPayload doesn't have placeholder, we don't need this checking and the error message is not reflecting correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point. We don't need to throw exception here. I was mostly trying to reflect this test case

return result;
}

protected boolean isNotPlainString(String value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user input {"key1": "123"}, we will detect "123" as not plain String?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From line 282
isNotPlainString(paramValue) ? paramValue : "\"" + paramValue + "\"";

It will return 123 rather than "123" which not what user expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. So if user provides a number with "" ("123"), although it's a number we still should send value as "123"?
  2. if user provide a number without "" (123), in that case I suppose we want to send the value as 123?
  3. What about boolean values? Same idea?

Copy link
Collaborator

@ylwu-amzn ylwu-amzn Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example "{ \"texts\": ${parameters.texts}, \"truncate\": ${parameters.truncate} }" , if user input "truncate": "123" in parameters when predict, will we pass \"truncate\": 123 to model with your PR?

@@ -254,8 +256,7 @@ public <T> T createPredictPayload(Map<String, String> parameters) {
if (predictAction.isPresent() && predictAction.get().getRequestBody() != null) {
String payload = predictAction.get().getRequestBody();
payload = fillNullParameters(parameters, payload);
StringSubstitutor substitutor = new StringSubstitutor(parameters, "${parameters.", "}");
payload = substitutor.replace(payload);
payload = applyCustomSubstitution(parameters, payload);
if (!isJson(payload)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my local testing, I found this can return false on "valid" json. The issue was that parameter values needed to be escaped. I can make a separate PR for that, but thought Id mention it here since there's related code in this PR for escaping parameter values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing I saw, at this point payload is supposed to replaced with the actual value:

like: "{ \"texts\": ${parameters.texts}, \"truncate\": ${parameters.truncate} }" --> "{ \"texts\": [\"hello world\"], \"truncate\": \"END\" }" which is a valid JSON.

Could you please share your use case where you get false for a "valid" JSON?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am basically taking a bunch of text from my OpenSearch cluster (as search results/hits) and passing it as part of the messages parameter to OpenAI (search hit -> message). I don't know which character in my text caused the issue, but to get around it, I applied a patch locally to always do escapeJson on the messages and got around the issue. So, what I am trying to say is that if the text is not properly escaped for Json, you can get IllegalArgumentException. I guess this is not a comment specific to your PR. I am not pointing out an issue with the custom substitution logic per se. Let me know if you want me to open a new issue to track this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@austintlee I think you are using 2.x branch. We have some bug fix in 2.9 branch, we just backported them to 2.x branch. Please rebase your code and retest.

}
}

result = StringEscapeUtils.unescapeJava(result); // Unescape Unicode escape sequences
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I am not sure if this is sufficient to avoid valid values causing isJson() to fail as I mentioned above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain this little bit more for me?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yaliang answered my question above.

}
String result = inputPayload;

Pattern pattern = Pattern.compile("\\$\\{parameters\\.(\\w+)\\}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pull this out as a class static?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants