-
Notifications
You must be signed in to change notification settings - Fork 64
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
adding executeAPI #165
adding executeAPI #165
Conversation
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
The tests will fail until PR #159 gets merged. |
@dhrubo-os Can you send the criteria for validating the json? |
I'm talking about something simple like this. |
And for the simple calculator what I was instructing to use is here:
|
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
Can we please check why the integration test is failing here?
|
25cbdaa
to
7d01104
Compare
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
This PR closed for some reason |
:rtype: dict | ||
""" | ||
|
||
if not isinstance(input_json, dict): |
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.
import json
def is_valid_json(input_string):
try:
json.loads(input_string)
return True
except ValueError:
return False
Can't we do something like 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.
It will return false if the input is dictionary
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.
Is that okay?
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.
you mean if the input is {"a":"abc"}
then it will fail?
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, I think so. json.loads accepts only string or bytearray
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 checked using this function:
Provided input string is valid: {"a":"abc"}
Provided input string is valid: {"operation": "max", "input_data": [1.0, 2.0, 3.0]}
Provided input string is not valid: zaa
Provided input string is valid: {"index_name": "rca-index","attribute_field_names": ["attribute"],"aggregations": [{"sum": {"sum": {"field": "value"}}}],"time_field_name": "timestamp","start_time": 1620630000000,"end_time": 1621234800000,"min_time_interval": 86400000,"num_outputs": 10}
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.
The code snippet you provided (if not isinstance(input_json, dict):
) does not directly check whether a given input is a valid JSON string or not. The isinstance() function in Python checks if an object is an instance of a particular class or data type. In this case, it checks if the input_json variable is not an instance of a dictionary (dict).
While a valid JSON string can be represented as a dictionary object in Python, this check alone does not guarantee that the input is a valid JSON string. It only verifies that the input_json is not a dictionary.
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.
Hmm, I will double check whether it accepts dictionaries.
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 input is not an instance of a dictionary, json.loads will be called. Then, if it’s not a deserializable json, it will raise an exception. Otherwise, it returns a dictionary that is used in the query.
Also can you please check why the integration test is failing here? |
I'll prioritize this commit. Let's close out this commit asap if possible. Thanks |
The problem is with the TESTDATA_SYNTHETIC_QUERY_ZIP constant path string. |
It just concatenates the double dots as the other 2 arguments. |
@@ -33,7 +33,9 @@ | |||
MODEL_CONFIG_FILE_NAME = "ml-commons_model_config.json" | |||
|
|||
TEST_FOLDER = os.path.join(PROJECT_DIR, "test_model_files") | |||
TESTDATA_SYNTHETIC_QUERY_ZIP = os.path.join(PROJECT_DIR, "..", "synthetic_queries.zip") | |||
TESTDATA_SYNTHETIC_QUERY_ZIP = os.path.join( |
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.
Looks like you are changing the path here? Can we revert this to pass the integration test?
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.
Oh, I don't remember changing it. Will fix.
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
Codecov Report
@@ Coverage Diff @@
## main #165 +/- ##
==========================================
+ Coverage 90.76% 90.79% +0.03%
==========================================
Files 36 37 +1
Lines 4027 4042 +15
==========================================
+ Hits 3655 3670 +15
Misses 372 372
|
def __init__(self, os_client: OpenSearch): | ||
self._client = os_client | ||
|
||
def _execute(self, algorithm_name: str, input_json: dict) -> dict: |
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.
first of all I think we should expect a string for input_json
not a dict.
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.
Are you sure? Wouldn’t that be inconvenient for the user?
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 you can see in the post requests customers are used to send these values as string into the api. I believe this will keep the experience same.
For dict, customer eventually need to build the dict.
May be we can expect both (string and dict) if you think that can improve customer experience?
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.
Right now, it accepts both dict and string. Should I change anything?
@@ -72,6 +72,18 @@ def test_init(): | |||
assert type(ml_client._model_uploader) == ModelUploader | |||
|
|||
|
|||
def test_execute(): |
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 please add another test to show it works with string also?
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
|
||
raised = False | ||
try: | ||
input_json = '{"operation": "max", "input_data": [1.0, 2.0, 3.0]}' |
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 just realized, we should get result from this input. In the try block can we also match value? In both cases.
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.
Also can we try to cover the catch condition. I'm planning to add start a initiative to start covering for the except cases. This can be good start. Pls lmk if you have any question.
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 elaborate more on the covering except part? What do you men by cover?
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.
Nevermind, ignore my last comment. Approving the PR.
Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com>
* adding executeAPI Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * updating documentation Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing code and test Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing code Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * fixing tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * checking output value in integration tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> --------- Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> (cherry picked from commit 8eb26eb)
* adding executeAPI Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * updating documentation Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing code and test Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing code Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * fixing tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * changing tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> * checking output value in integration tests Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> --------- Signed-off-by: Alibi Zhenis <alibizhenis4@gmail.com> (cherry picked from commit 8eb26eb) Co-authored-by: Alibi Zhenis <92104549+AlibiZhenis@users.noreply.github.com>
Issues Resolved
Closes #164
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.