Skip to content

Commit

Permalink
Merge pull request #102 from meedan/cv2-5001-loosen-typing
Browse files Browse the repository at this point in the history
CV2-5001 remove parsing restriction on output
  • Loading branch information
DGaffney authored Aug 1, 2024
2 parents ed55ff3 + 14d7b5e commit 90893fc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def handle_fingerprinting_error(self, e):
if attr == "__traceback__":
error_context[attr] = '\n'.join(traceback.format_tb(getattr(e, attr)))
else:
error_context[attr] = getattr(e, attr)
error_context[attr] = str(getattr(e, attr))
capture_custom_message("Error during fingerprinting for {self.model_name}", 'info', error_context)
return schemas.ErrorResponse(error=str(e), error_details=error_context)

Expand Down
6 changes: 3 additions & 3 deletions lib/queue/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def send_callbacks(self) -> List[schemas.Message]:
if messages_with_queues:
logger.info(f"About to respond to: ({messages_with_queues})")
bodies = [
schemas.parse_message(json.loads(message.body))
json.loads(message.body)
for message, queue in messages_with_queues
]
for body in bodies:
Expand All @@ -58,10 +58,10 @@ def send_callback(self, message):
"""
logger.info(f"Message for callback is: {message}")
try:
callback_url = message.body.callback_url
callback_url = message.get("body", {}).get("callback_url")
response = requests.post(
callback_url,
json=message.dict(),
json=message,
# headers={"Content-Type": "application/json"},
)
# check for error with the callback
Expand Down
6 changes: 3 additions & 3 deletions test/lib/queue/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def test_send_callbacks(self):

@patch('lib.queue.processor.requests.post')
def test_send_callback(self, mock_post):
message_body = schemas.parse_message({"body": {"callback_url": "http://example.com", "text": "This is a test", "id": 123, "result": {"hash_value": [1,2,3]}}, "model_name": "mean_tokens__Model"})
message_body = {"body": {"callback_url": "http://example.com", "text": "This is a test", "id": 123, "result": {"hash_value": [1,2,3]}}, "model_name": "mean_tokens__Model"}
self.queue_processor.send_callback(message_body)
mock_post.assert_called_once_with("http://example.com", json=message_body.dict())
mock_post.assert_called_once_with("http://example.com", json=message_body)

@patch('lib.queue.processor.requests.post')
def test_send_callback_failure(self, mock_post):
mock_post.side_effect = Exception("Request Failed!")
message_body = schemas.parse_message({"body": {"callback_url": "http://example.com", "text": "This is a test", "id": 123, "result": {"hash_value": [1,2,3]}}, "model_name": "mean_tokens__Model"})
message_body = {"body": {"callback_url": "http://example.com", "text": "This is a test", "id": 123, "result": {"hash_value": [1,2,3]}}, "model_name": "mean_tokens__Model"}
with self.assertLogs(level='ERROR') as cm:
self.queue_processor.send_callback(message_body)
self.assertIn("Failed with Request Failed! on http://example.com with message of", cm.output[0])
Expand Down

0 comments on commit 90893fc

Please sign in to comment.