From 67669efba456ab3893652d6c19e155ea41c60c70 Mon Sep 17 00:00:00 2001 From: matt-bernstein <60152561+matt-bernstein@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:38:16 -0500 Subject: [PATCH] fix: DIA-1660: Adala errors are not reported as ConstrainedGenerationError when they should be (#259) --- adala/runtimes/_litellm.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/adala/runtimes/_litellm.py b/adala/runtimes/_litellm.py index bd2a191b..0cb49ae8 100644 --- a/adala/runtimes/_litellm.py +++ b/adala/runtimes/_litellm.py @@ -306,7 +306,9 @@ def record_to_record( ) # Catch case where the model does not return a properly formatted output - if type(e).__name__ == "ValidationError" and "Invalid JSON" in str(e): + # AttributeError is an instructor bug: https://github.com/instructor-ai/instructor/pull/1103 + # > AttributeError: 'NoneType' object has no attribute '_raw_response' + if type(e).__name__ in {"ValidationError", "AttributeError"}: e = ConstrainedGenerationError() # there are no other known errors to catch dct = _log_llm_exception(e) @@ -464,7 +466,13 @@ async def batch_to_batch( ) # Catch case where the model does not return a properly formatted output - if type(e).__name__ == "ValidationError" and "Invalid JSON" in str(e): + # AttributeError is an instructor bug: https://github.com/instructor-ai/instructor/pull/1103 + # > AttributeError: 'NoneType' object has no attribute '_raw_response' + if type(e).__name__ in {"ValidationError", "AttributeError"}: + logger.error( + f"Converting error to ConstrainedGenerationError: {str(e)}" + ) + logger.debug(f"Traceback:\n{traceback.format_exc()}") e = ConstrainedGenerationError() # the only other instructor error that would be thrown is IncompleteOutputException due to max_tokens reached dct = _log_llm_exception(e)