From 7fb934073d451ea69927a0ac673b94cf5881e6c1 Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Mon, 15 Apr 2024 15:45:01 +0000 Subject: [PATCH 1/5] Fixes #76: Add the models key to the result store in the blob storage --- app.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 43b412b..8075368 100644 --- a/app.py +++ b/app.py @@ -94,6 +94,7 @@ class MaxContentLengthWarning(APIWarnings): [ 'request_function', 'name', + 'version', 'endpoint', 'api_key', 'content_type', @@ -305,7 +306,9 @@ async def inference_request(): container_client, folder_name, image_bytes, hash_value ) - for idx, model in enumerate(pipelines_endpoints.get(pipeline_name)): + pipeline = pipelines_endpoints.get(pipeline_name) + + for idx, model in enumerate(pipeline): print(f"Entering {model.name.upper()} model") # TODO: Transform into logging result_json = await model.request_function(model, cache_json_result[idx]) cache_json_result.append(result_json) @@ -317,7 +320,7 @@ async def inference_request(): cache_json_result[-1], imageDims, area_ratio, color_format ) - result_json_string = json.dumps(processed_result_json) + result_json_string = await record_model(pipeline, processed_result_json) # upload the inference results to the user's container as async task app.add_background_task( @@ -406,6 +409,13 @@ async def test(): return CACHE["endpoints"], 200 + +async def record_model(pipeline: namedtuple, result: list): + new_entry = [{"name": model.name, "version": model.version} for model in pipeline] + result[0]["models"] = new_entry + return json.dumps(result, indent=4) + + async def fetch_json(repo_URL, key, file_path): """ Fetches JSON document from a GitHub repository and caches it @@ -444,6 +454,7 @@ async def get_pipelines(): m = Model( request_function.get(model.get("api_call_function")), model.get("model_name"), + model.get("version"), # To protect sensible data (API key and model endpoint), we encrypt it when # it's pushed into the blob storage. Once we retrieve the data here in the # backend, we need to decrypt the byte format to recover the original From fbfadc4fc5e3cef09a1defaaebe2c80e992e503e Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Mon, 15 Apr 2024 15:56:29 +0000 Subject: [PATCH 2/5] fixes 76: update tests with new key value --- app.py | 1 + tests/test_inference_request.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 8075368..f82a9ab 100644 --- a/app.py +++ b/app.py @@ -399,6 +399,7 @@ async def test(): m = Model( request_function["test"], "test_model1", + 1, "http://localhost:8080/test_model1", "test_api_key", "application/json", diff --git a/tests/test_inference_request.py b/tests/test_inference_request.py index 8fac0d6..4b7f9b0 100644 --- a/tests/test_inference_request.py +++ b/tests/test_inference_request.py @@ -65,7 +65,8 @@ def test_inference_request_successful(self, mock_container): "score", "topN", "overlapping", - "overlappingIndices" + "overlappingIndices", + "models" } # Test the answers from inference_request From 66915f5bfc3c25d1d47d1b41d91fc8a3e00a39d6 Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Tue, 16 Apr 2024 11:04:31 -0400 Subject: [PATCH 3/5] Add NACHET_MAX_CONTENT_LENGTH_MEGABYTES to README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d78e14d..fc4069f 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,11 @@ backend to function, you will need to add the missing values: accepted by the backend - **NACHET_VALID_DIMENSION**: Contains the valid dimensions for an image to be accepted in the backend. +- **NACHET_MAX_CONTENT_LENGTH_MEGABYTES**: Set the maximum size of the file that can be + uploaded to the backend. Needs to be the same size as the + `client_max_body_size` + [value](https://github.com/ai-cfia/howard/blob/dedee069f051ba743122084fcb5d5c97c2499359/kubernetes/aks/apps/nachet/base/nachet-ingress.yaml#L13) + set from the deployment in Howard. #### DEPRECATED From 8ad1db2d62491696b81f7a0f04b3195e2c310364 Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Tue, 16 Apr 2024 15:27:13 +0000 Subject: [PATCH 4/5] fixes #76: correct env. variable name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc4069f..8cd3534 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ backend to function, you will need to add the missing values: accepted by the backend - **NACHET_VALID_DIMENSION**: Contains the valid dimensions for an image to be accepted in the backend. -- **NACHET_MAX_CONTENT_LENGTH_MEGABYTES**: Set the maximum size of the file that can be +- **NACHET_MAX_CONTENT_LENGTH**: Set the maximum size of the file that can be uploaded to the backend. Needs to be the same size as the `client_max_body_size` [value](https://github.com/ai-cfia/howard/blob/dedee069f051ba743122084fcb5d5c97c2499359/kubernetes/aks/apps/nachet/base/nachet-ingress.yaml#L13) From 5b8698dca7c53f533b30c828f1a3b6a2b239a403 Mon Sep 17 00:00:00 2001 From: Maxence Guindon Date: Tue, 23 Apr 2024 16:11:35 -0400 Subject: [PATCH 5/5] Remove duplicated namedtuple.py --- app.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app.py b/app.py index adf3d8b..294279d 100644 --- a/app.py +++ b/app.py @@ -72,19 +72,6 @@ class MaxContentLengthWarning(APIWarnings): NACHET_DATA = os.getenv("NACHET_DATA") -Model = namedtuple( - 'Model', - [ - 'entry_function', - 'name', - 'endpoint', - 'api_key', - 'inference_function', - 'content_type', - 'deployment_platform', - ] -) - try: VALID_EXTENSION = json.loads(os.getenv("NACHET_VALID_EXTENSION")) VALID_DIMENSION = json.loads(os.getenv("NACHET_VALID_DIMENSION"))