Skip to content

Commit

Permalink
fix: DIA-1660: Adala errors are not reported as ConstrainedGeneration…
Browse files Browse the repository at this point in the history
…Error when they should be
  • Loading branch information
matt-bernstein committed Nov 21, 2024
1 parent 9df517b commit 196349d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions adala/runtimes/_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.error(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)
Expand Down

0 comments on commit 196349d

Please sign in to comment.