From 68ae964d449bcd9d934c81d30dc6b6e7d2619ac5 Mon Sep 17 00:00:00 2001 From: Yusuf Olokoba Date: Thu, 16 Nov 2023 07:53:49 -0500 Subject: [PATCH] Fix JSON serialization error in CLI --- Changelog.md | 2 +- fxn/cli/auth.py | 4 ++-- fxn/cli/env.py | 5 ++--- fxn/cli/predict.py | 2 +- fxn/cli/predictors.py | 10 +++++----- fxn/services/prediction.py | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1864518..a785354 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,5 @@ ## 0.0.25 -*INCOMPLETE* ++ Fixed JSON serialization errors when using the CLI to perform some operations. ## 0.0.24 + Added `Function` client class to replace functions on individual API types. diff --git a/fxn/cli/auth.py b/fxn/cli/auth.py index 60c6876..102bef5 100644 --- a/fxn/cli/auth.py +++ b/fxn/cli/auth.py @@ -17,7 +17,7 @@ def login ( ): fxn = Function(access_key) user = fxn.users.retrieve() - user = dict(user) if user else None + user = user.model_dump() if user else None _set_access_key(access_key if user is not None else None) print_json(data=user) @@ -25,7 +25,7 @@ def login ( def auth_status (): fxn = Function(get_access_key()) user = fxn.users.retrieve() - user = dict(user) if user else None + user = user.model_dump() if user else None print_json(data=user) @app.command(name="logout", help="Logout from Function.") diff --git a/fxn/cli/env.py b/fxn/cli/env.py index 8b9a374..1faedf7 100644 --- a/fxn/cli/env.py +++ b/fxn/cli/env.py @@ -17,7 +17,7 @@ def list_envs ( ): fxn = Function(get_access_key()) environments = fxn.environment_variables.list(organization=organization) - environments = [dict(env) for env in environments] + environments = [env.model_dump() for env in environments] print_json(data=environments) @app.command(name="create", help="Create an environment variable.") @@ -28,8 +28,7 @@ def create_env ( ): fxn = Function(get_access_key()) environment = fxn.environment_variables.create(name=name, value=value, organization=organization) - environment = dict(environment) - print_json(data=environment) + print_json(data=environment.model_dump()) @app.command(name="delete", help="Delete an environment variable.") def delete_env ( diff --git a/fxn/cli/predict.py b/fxn/cli/predict.py index 538926d..8fbb296 100644 --- a/fxn/cli/predict.py +++ b/fxn/cli/predict.py @@ -42,7 +42,7 @@ def predict ( results = [_serialize_value(value) for value in prediction.results] object.__setattr__(prediction, "results", results) # Print - print_json(data=dict(prediction)) + print_json(data=prediction.model_dump()) # Show images for image in images: image.show() diff --git a/fxn/cli/predictors.py b/fxn/cli/predictors.py index 955be85..3cc1d62 100644 --- a/fxn/cli/predictors.py +++ b/fxn/cli/predictors.py @@ -17,7 +17,7 @@ def retrieve_predictor ( ): fxn = Function(get_access_key()) predictor = fxn.predictors.retrieve(tag) - predictor = dict(predictor) if predictor else None + predictor = predictor.model_dump() if predictor else None print_json(data=predictor) def list_predictors ( @@ -33,7 +33,7 @@ def list_predictors ( offset=offset, count=count ) - predictors = [dict(predictor) for predictor in predictors] if predictors is not None else None + predictors = [predictor.model_dump() for predictor in predictors] if predictors is not None else None print_json(data=predictors) def search_predictors ( @@ -43,7 +43,7 @@ def search_predictors ( ): fxn = Function(get_access_key()) predictors = fxn.predictors.search(query=query, offset=offset, count=count) - predictors = [dict(predictor) for predictor in predictors] + predictors = [predictor.model_dump() for predictor in predictors] print_json(data=predictors) def create_predictor ( @@ -72,7 +72,7 @@ def create_predictor ( license=license, overwrite=overwrite ) - print_json(data=dict(predictor)) + print_json(data=predictor.model_dump()) def delete_predictor ( tag: str=Argument(..., help="Predictor tag.") @@ -86,4 +86,4 @@ def archive_predictor ( ): fxn = Function(get_access_key()) predictor = fxn.predictors.archive(tag) - print_json(data=dict(predictor)) \ No newline at end of file + print_json(data=predictor.model_dump()) \ No newline at end of file diff --git a/fxn/services/prediction.py b/fxn/services/prediction.py index 265cafb..1c48142 100644 --- a/fxn/services/prediction.py +++ b/fxn/services/prediction.py @@ -52,7 +52,7 @@ def create ( """ # Serialize inputs key = uuid4().hex - inputs = [{ "name": name, **dict(self.from_value(value, name, key=key)) } for name, value in inputs.items()] + inputs = [{ "name": name, **self.from_value(value, name, key=key).model_dump() } for name, value in inputs.items()] # Query response = self.client.query(f""" mutation ($input: CreatePredictionInput!) {{ @@ -93,7 +93,7 @@ async def stream ( """ # Serialize inputs key = uuid4().hex - inputs = { name: dict(self.from_value(value, name, key=key)) for name, value in inputs.items() } + inputs = { name: self.from_value(value, name, key=key).model_dump() for name, value in inputs.items() } # Request url = f"{self.client.api_url}/predict/{tag}?stream=true&rawOutputs=true&dataUrlLimit={data_url_limit}" headers = {