Skip to content

Commit d26f49e

Browse files
committed
refactor: Add version check for langchain_nvidia_ai_endpoints
1 parent 7aa5199 commit d26f49e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

nemoguardrails/llm/providers/providers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
2121
Additional providers can be registered using the `register_llm_provider` function.
2222
"""
23+
2324
import asyncio
2425
import logging
26+
from importlib.metadata import PackageNotFoundError, version
2527
from typing import Any, Dict, List, Optional, Type
2628

2729
from langchain.base_language import BaseLanguageModel
@@ -33,6 +35,7 @@
3335
from langchain.schema.output import GenerationChunk
3436
from langchain_community import llms
3537
from langchain_community.llms import HuggingFacePipeline
38+
from packaging import version as pkg_version
3639

3740
from nemoguardrails.rails.llm.config import Model
3841

@@ -244,7 +247,16 @@ def get_llm_provider(model_config: Model) -> Type[BaseLanguageModel]:
244247

245248
from ._langchain_nvidia_ai_endpoints_patch import ChatNVIDIA
246249

250+
# Check the version
251+
package_version = version("langchain_nvidia_ai_endpoints")
252+
253+
if _parse_version(package_version) < (0, 2, 0):
254+
raise ValueError(
255+
"langchain_nvidia_ai_endpoints version must be 0.2.0 or above."
256+
" Please upgrade it with `pip install langchain-nvidia-ai-endpoints --upgrade`."
257+
)
247258
return ChatNVIDIA
259+
248260
except ImportError:
249261
raise ImportError(
250262
"Could not import langchain_nvidia_ai_endpoints, please install it with "
@@ -271,3 +283,7 @@ def get_llm_provider(model_config: Model) -> Type[BaseLanguageModel]:
271283
def get_llm_provider_names() -> List[str]:
272284
"""Returns the list of supported LLM providers."""
273285
return list(sorted(list(_providers.keys())))
286+
287+
288+
def _parse_version(version_str):
289+
return tuple(map(int, (version_str.split("."))))

0 commit comments

Comments
 (0)