Skip to content

Commit

Permalink
Fix JSON serialization error in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
olokobayusuf committed Nov 16, 2023
1 parent 0a70048 commit 68ae964
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions fxn/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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)

@app.command(name="status", help="Get current authentication status.")
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.")
Expand Down
5 changes: 2 additions & 3 deletions fxn/cli/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion fxn/cli/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions fxn/cli/predictors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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.")
Expand All @@ -86,4 +86,4 @@ def archive_predictor (
):
fxn = Function(get_access_key())
predictor = fxn.predictors.archive(tag)
print_json(data=dict(predictor))
print_json(data=predictor.model_dump())
4 changes: 2 additions & 2 deletions fxn/services/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!) {{
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 68ae964

Please sign in to comment.