fix: Improve error handling for NVIDIA model component (#7484)

fix: ignore ConnectionError in  NVIDIA model component in case there's no internet connection

- Added logging for connection issues when accessing the NVIDIA API.
- Implemented exception handling for ConnectionError, MaxRetryError, and NameResolutionError to improve robustness and user feedback.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-04-07 15:40:50 -03:00 committed by GitHub
commit eeb443bdc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,9 @@
from typing import Any
from loguru import logger
from requests.exceptions import ConnectionError # noqa: A004
from urllib3.exceptions import MaxRetryError, NameResolutionError
from langflow.base.models.model import LCModelComponent
from langflow.field_typing import LanguageModel
from langflow.field_typing.range_spec import RangeSpec
@ -19,6 +23,12 @@ class NVIDIAModelComponent(LCModelComponent):
except ImportError as e:
msg = "Please install langchain-nvidia-ai-endpoints to use the NVIDIA model."
raise ImportError(msg) from e
except (ConnectionError, MaxRetryError, NameResolutionError):
logger.warning(
"Failed to connect to NVIDIA API. Model list may be unavailable."
" Please check your internet connection and API credentials."
)
all_models = []
inputs = [
*LCModelComponent._base_inputs,