Scrapegraph-ai/scrapegraphai/models/nvidia.py
copilot-swe-agent[bot] 8cf81c986a Add documentation explaining __new__ usage in Nvidia class
Co-authored-by: VinciGit00 <88108002+VinciGit00@users.noreply.github.com>
2025-11-26 20:01:37 +00:00

33 lines
1.1 KiB
Python

"""
NVIDIA Module
"""
class Nvidia:
"""
A wrapper for the ChatNVIDIA class that provides default configuration
and could be extended with additional methods if needed.
Note: This class uses __new__ instead of __init__ because langchain_nvidia_ai_endpoints
is an optional dependency. We cannot inherit from ChatNVIDIA at class definition time
since the module may not be installed. The __new__ method allows us to lazily import
and return a ChatNVIDIA instance only when Nvidia() is instantiated.
Args:
llm_config (dict): Configuration parameters for the language model.
"""
def __new__(cls, **llm_config):
try:
from langchain_nvidia_ai_endpoints import ChatNVIDIA
except ImportError:
raise ImportError(
"""The langchain_nvidia_ai_endpoints module is not installed.
Please install it using `pip install langchain-nvidia-ai-endpoints`."""
)
if "api_key" in llm_config:
llm_config["nvidia_api_key"] = llm_config.pop("api_key")
return ChatNVIDIA(**llm_config)