Skip to content

Commit

Permalink
Merge pull request #117 from meedan/cv2-5050-add-context-to-transform…
Browse files Browse the repository at this point in the history
…er-vectorization-failures

CV2-5050 add additional context when transformer vectorization fails
  • Loading branch information
DGaffney authored Nov 4, 2024
2 parents 5d6d98b + d18916a commit 5b3db09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/model/generic_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _vectorize_and_cache(self, docs_to_process: List[schemas.Message], texts_to_
doc.body.result = vector
Cache.set_cached_result(doc.body.content_hash, vector)
except Exception as e:
self.handle_fingerprinting_error(e)
self.handle_fingerprinting_error(e, 500, {"texts_to_vectorize": texts_to_vectorize})

def vectorize(self, texts: List[str]) -> List[List[float]]:
"""
Expand Down
4 changes: 3 additions & 1 deletion lib/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ def get_tempfile(self) -> Any:
def process(self, messages: Union[List[schemas.Message], schemas.Message]) -> List[schemas.Message]:
return []

def handle_fingerprinting_error(self, e: Exception, response_code: int = 500) -> schemas.ErrorResponse:
def handle_fingerprinting_error(self, e: Exception, response_code: int = 500, additional_context: dict = {}) -> schemas.ErrorResponse:
error_context = {"error": str(e)}
for attr in ["__cause__", "__context__", "args", "__traceback__"]:
if attr in dir(e):
if attr == "__traceback__":
error_context[attr] = '\n'.join(traceback.format_tb(getattr(e, attr)))
else:
error_context[attr] = str(getattr(e, attr))
for k,v in additional_context.items():
error_context[k] = v
capture_custom_message(f"Error during fingerprinting for {self.model_name}", 'error', error_context)
return schemas.ErrorResponse(error=str(e), error_details=error_context, error_code=response_code)

Expand Down

0 comments on commit 5b3db09

Please sign in to comment.