-
Notifications
You must be signed in to change notification settings - Fork 177
Parameter Passing for Predict via Remote Connector #4121
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
Conversation
Signed-off-by: Shiqi Xia <[email protected]>
Signed-off-by: Shiqi Xia <[email protected]>
Signed-off-by: Shiqi Xia <[email protected]>
62c5b93
to
42fc5a5
Compare
return (T) parameters.get("http_body"); | ||
} | ||
|
||
public String removeMissingParameterFields(String payload, Map<String, String> params) { |
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.
Can you add description for this function?
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.
Done.
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 think we don't need remove the unused field. We should keep consistent behavior with previous code. I.e. if user set a parameter in template and don't provide values, we just keep it. Otherwise it may change the behavior at user side
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 understand. I’ve updated the code to follow this logic – now it keeps the unused fields consistent with the previous behavior.
import java.util.Map; | ||
import java.util.Optional; | ||
import java.io.IOException; | ||
import java.util.*; |
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.
we should aviod using import *, and restore to the previous import
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.
Done.
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.core.xcontent.NamedXContentRegistry; | ||
import org.opensearch.core.xcontent.*; |
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.
same as 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.
Done.
|
||
HashMap<String, String> paramMap = new HashMap<>(); | ||
for (Map.Entry<String, Object> entry : tempMap.entrySet()) { | ||
paramMap.put(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null); |
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 the Object is a map/list type, the toString by default returns their address in memory instead of a json, it seems not correct here, do you have test cases to cover this case?
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’ve addressed this issue by updating the code so that all types except basic types and String are serialized to JSON strings. Also added a unit test.
The code coverage in this PR is little bit low, can you add more UTs to increase the coverage? |
I've already added UT for it. But the Codecov Report hasn't been updated yet. Could you please allow CI/CD so it can rerun the test? |
HashMap<String, String> paramMap = new HashMap<>(); | ||
for (Map.Entry<String, Object> entry : tempMap.entrySet()) { | ||
Object value = entry.getValue(); | ||
if (value == null) { | ||
paramMap.put(entry.getKey(), null); | ||
} else if (value instanceof String) { | ||
paramMap.put(entry.getKey(), value.toString()); | ||
} else { | ||
try { | ||
String jsonValue = StringUtils.MAPPER.writeValueAsString(value); | ||
paramMap.put(entry.getKey(), jsonValue); | ||
} catch (JsonProcessingException e) { | ||
paramMap.put(entry.getKey(), null); | ||
} |
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 part can be replaced with the existing util method: getParameterMap
in org.opensearch.ml.common.utils.StringUtils
, right? A good practice in coding is reusing and avoid duplication.
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.
Yes, you are right. I’ve updated the code to reuse getParameterMap
from StringUtils
to avoid duplication. Thanks for the suggestion!
Signed-off-by: Shiqi Xia <[email protected]>
Description
This PR adds support for parameter propagation in the predict API when using
text_embedding
function by ensuring user-supplied parameters are correctly merged into the connector's request_body and included in the outgoing request.Related Issues
Resolves #4105
Check List
--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.