Skip to content
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

Wip 369 doc to models #227

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/lomas_client/libraries/smartnoise_synth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Type

from lomas_core.models.requests import (
SmartnoiseSynthDummyQueryModel,
Expand Down Expand Up @@ -38,6 +38,7 @@ def cost(
constraints: dict = {},
) -> Optional[CostResponse]:
"""This function estimates the cost of executing a SmartNoise query.

Args:
synth_name (str): name of the Synthesizer model to use.
Available synthesizer are
Expand Down Expand Up @@ -113,6 +114,7 @@ def query(
seed: int = DUMMY_SEED,
) -> Optional[QueryResponse]:
"""This function executes a SmartNoise Synthetic query.

Args:
synth_name (str): name of the Synthesizer model to use.
Available synthesizer are
Expand Down Expand Up @@ -181,6 +183,7 @@ def query(
"condition": condition,
"nb_samples": nb_samples,
}
request_model: Type[SmartnoiseSynthRequestModel]
if dummy:
endpoint = "dummy_smartnoise_synth_query"
body_dict["dummy_nb_rows"] = nb_rows
Expand Down
31 changes: 19 additions & 12 deletions client/lomas_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
InvalidQueryException,
UnauthorizedAccessException,
)
from lomas_core.models.exceptions import (
ExternalLibraryExceptionModel,
InternalServerExceptionModel,
InvalidQueryExceptionModel,
LomasServerExceptionTypeAdapter,
UnauthorizedAccessExceptionModel,
)


def raise_error(response: requests.Response) -> str:
Expand All @@ -21,18 +28,18 @@ def raise_error(response: requests.Response) -> str:
Raise:
Server Error
"""
error_message = response.json()
if response.status_code == status.HTTP_400_BAD_REQUEST:
raise InvalidQueryException(error_message["InvalidQueryException"])
if response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY:
raise ExternalLibraryException(
error_message["library"], error_message["ExternalLibraryException"]
)
if response.status_code == status.HTTP_403_FORBIDDEN:
raise UnauthorizedAccessException(error_message["UnauthorizedAccessException"])
if response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR:
raise InternalServerException(error_message["InternalServerException"])
raise InternalServerException(f"Unknown {InternalServerException}")
error_model = LomasServerExceptionTypeAdapter.validate_json(response.json())
match error_model:
case InvalidQueryExceptionModel():
raise InvalidQueryException(error_model.message)
case ExternalLibraryExceptionModel():
raise ExternalLibraryException(error_model.library, error_model.message)
case UnauthorizedAccessExceptionModel():
raise UnauthorizedAccessException(error_model.message)
case InternalServerExceptionModel():
raise InternalServerException("Internal Server Exception.")
case _:
raise InternalServerException(f"Unknown {InternalServerException}")


def validate_synthesizer(synth_name: str, return_model: bool = False):
Expand Down
Loading
Loading