Skip to content

Commit

Permalink
#Issue 60: Add a default key for pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxence Guindon committed Apr 2, 2024
1 parent 91f1b46 commit f8710c7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
5 changes: 2 additions & 3 deletions docs/nachet-model-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ A list of common error models returns to the backend.
## Pipeline and model data

In order to dynamically build the pipeline in the backend from the model, the
following data structure was designed. For now, the pipelines will have two keys for their names (`model_name`, `piepline_name`) to support the frontend code until it is changed to get the name of the pipeline with the correct key.
following data structure was designed. For now, the pipelines will have two keys for their names (`model_name`, `pipeline_name`) to support the frontend code until it is changed to get the name of the pipeline with the correct key.

```yaml
version:
Expand All @@ -166,6 +166,7 @@ pipelines:
dataset:
metrics:
identifiable:
default:

models:
- task:
Expand All @@ -175,8 +176,6 @@ models:
inference_function:
content_type:
deployment_platform:
azure:
# support azure, google, huggingface, aws
endpoint_name:
model_name:
created_by:
Expand Down
4 changes: 1 addition & 3 deletions pipeline_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pipelines:
dataset:
metrics:
identifiable:
default:

models:
- tasks:
Expand All @@ -24,9 +25,6 @@ models:
inference_function:
content_type:
deployment_platform:
platform:
# example of deployment_platform
# azure: name_of_endpoint
endpoint_name:
model_name:
created_by:
Expand Down
12 changes: 11 additions & 1 deletion pipelines_version_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- The file must be a dictionary with the following keys: version, date,
pipelines, models.
- Supported formats are json, yaml and yml.
- At least one of the pipelines must be set as default (default: True).
- Refer to pipeline_template.yaml to see the expected structure of the file.
- The endpoint and API key in each model will be encrypted using the provided
decryption key.
Expand Down Expand Up @@ -58,6 +59,8 @@
BLOB_STORAGE_ACCOUNT_NAME = os.getenv("NACHET_BLOB_PIPELINE_NAME")
CONNECTION_STRING = os.getenv("NACHET_AZURE_STORAGE_CONNECTION_STRING")

NO_DEFAULT_MSG = "no pipeline was set as default, please set one as default by setting the default value as True"

class PipelineInsertionError(Exception):
pass

Expand Down Expand Up @@ -93,6 +96,7 @@ class Pipeline(BaseModel):
dataset: str
metrics: list
identifiable: list
default: bool

@field_validator ("*", mode="before", check_fields=True)
def validate_data(cls, v):
Expand All @@ -116,7 +120,7 @@ class Model(BaseModel):
api_key: str
inference_function: str
content_type: str
deployment_platform: dict
deployment_platform: str
endpoint_name: str
model_name: str
created_by: str
Expand Down Expand Up @@ -267,6 +271,12 @@ def pipeline_insertion(file_path:str) -> str:
)
try:
Data(**pipelines)
for pipeline in pipelines["pipelines"]:
if pipeline.get("default"):
print(f"pipeline {pipeline.get('pipeline_name')} is set as default")
break
else:
raise PipelineInsertionError(NO_DEFAULT_MSG)
except ValidationError as error:
raise PipelineInsertionError(error) from error

Expand Down
53 changes: 53 additions & 0 deletions tests/test_pipeline_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,58 @@ def test_pipeline_insertion_fail_validation(self, mock_os_path_exists, mock_yaml
with self.assertRaises(PipelineInsertionError):
pipeline_insertion("test_file.yaml")

@patch("pipelines_version_insertion.yaml_to_json")
@patch("os.path.exists")
def test_pipeline_insertion_fail_no_default(self, mock_os_path_exists, mock_yaml_to_json):
mock_os_path_exists.return_value = True
mock_yaml_to_json.return_value = {
"version": "0.0.0",
"date": "2021-01-01",
"pipelines": [
{
"models": ["test_model"],
"model_name": "p_test",
"pipeline_name": "p_test",
"created_by": "test",
"creation_date": "test",
"version": 1,
"description": "test",
"job_name": "test",
"dataset": "test",
"metrics": [],
"identifiable": [],
"default": False
}
],
"models": [
{
"task": "test",
"api_call_function": "test",
"endpoint": "test",
"api_key": "test",
"inference_function": "test",
"content_type": "test",
"deployment_platform": "test",
"endpoint_name": "test",
"model_name": "test_model",
"created_by": "test",
"creation_date": "test",
"version": 1,
"description": "test",
"job_name": "test",
"dataset": "test",
"metrics": ["test"],
"identifiable": ["test"]
}
],
}

expected = "no pipeline was set as default, please set one as default by setting the default value as True"
with self.assertRaises(PipelineInsertionError) as context:
pipeline_insertion("test_file.yaml")

self.assertEqual(str(context.exception), expected)
print(str(context.exception) == expected)

if __name__ == "__main__":
unittest.main()

0 comments on commit f8710c7

Please sign in to comment.