refactor: Update AnthropicModelComponent to handle ImportError gracefully

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-20 18:18:09 -03:00
commit 6b3a8b69bc

View file

@ -98,9 +98,9 @@ class AnthropicModelComponent(LCModelComponent):
try: try:
from anthropic import BadRequestError from anthropic import BadRequestError
except ImportError: except ImportError:
return return None
if isinstance(exception, BadRequestError): if isinstance(exception, BadRequestError):
message = exception.body.get("error", {}).get("message") # type: ignore message = exception.body.get("error", {}).get("message") # type: ignore
if message: if message:
return message return message
return return None