-
Notifications
You must be signed in to change notification settings - Fork 140
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. |
protected String applyCustomSubstitution(Map<String, String> parameters, String inputPayload) { | ||
|
||
if (parameters == null) { | ||
throw new IllegalArgumentException("Some parameter placeholder not filled in payload: input"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- So if user provides a number with
""
("123"
), although it's a number we still should send value as"123"
? - if user provide a number without
""
(123), in that case I suppose we want to send the value as123
? - What about boolean values? Same idea?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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+)\\}"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Description
[updating request field for the connectors]
Issues Resolved
[List any issues this PR will resolve]
Check List
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.