Skip to content

Commit

Permalink
implementing sample validataion code for classycat, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
ashkankzme committed Aug 15, 2024
1 parent 5229b1a commit 08662e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
23 changes: 20 additions & 3 deletions lib/model/classycat_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,28 @@ def validate_input(cls, data: Dict) -> None:
"""
Validate input data. Must be implemented by all child "Model" classes.
"""
pass
if "schema_id" not in data["parameters"] or data["parameters"]["schema_id"] == "":
raise PrestoBaseException("schema_id is required as input to classify", 422)

if "items" not in data["parameters"] or len(data["parameters"]["items"]) == 0:
raise PrestoBaseException("items are required as input to classify", 422)

for item in data["parameters"]["items"]:
if "id" not in item or item["id"] == "":
raise PrestoBaseException("id is required for each item", 422)
if "text" not in item or item["text"] == "":
raise PrestoBaseException("text is required for each item", 422)

@classmethod
def parse_input_message(cls, data: Dict) -> Any:
"""
Validate input data. Must be implemented by all child "Model" classes.
Parse input into appropriate response instances.
"""
return None
event_type = data['parameters']['event_type']
result_data = data.get('result', {})

if event_type == 'classify':
return ClassyCatBatchClassificationResponse(**result_data)
else:
logger.error(f"Unknown event type {event_type}")
raise PrestoBaseException(f"Unknown event type {event_type}", 422)
5 changes: 2 additions & 3 deletions lib/model/classycat_schema_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ def parse_input_message(cls, data: Dict) -> Any:
result_data = data.get('result', {})

if event_type == 'schema_create':
result_instance = ClassyCatSchemaResponse(**result_data)
return ClassyCatSchemaResponse(**result_data)
else:
logger.error(f"Unknown event type {event_type}")
raise PrestoBaseException(f"Unknown event type {event_type}", 422)

return result_instance
5 changes: 2 additions & 3 deletions lib/model/classycat_schema_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def parse_input_message(cls, data: Dict) -> Any:
result_data = data.get('result', {})

if event_type == 'schema_lookup':
result_instance = ClassyCatSchemaResponse(**result_data)
return ClassyCatSchemaResponse(**result_data)
else:
logger.error(f"Unknown event type {event_type}")
raise PrestoBaseException(f"Unknown event type {event_type}", 422)

return result_instance

0 comments on commit 08662e0

Please sign in to comment.