Skip to content

Commit

Permalink
feat(langchain): validate peer dependency (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D authored Feb 2, 2024
1 parent 70a889f commit db9f880
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/extensions/langchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
To use the following extension, first install it by running
:bash:`pip install 'ibm-generative-ai[langchain]'`.
.. admonition:: LangChain versions
:class: attention
Our LangChain extension depends on `langchain-core` library.
In case you are also using `langchain` library, please do ensure you are using version >= 0.1.0
to prevent possible bugs.
"""
26 changes: 26 additions & 0 deletions src/genai/extensions/langchain/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""Extension for LangChain library"""
import warnings
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as get_package_version

from packaging.version import parse as parse_version

from genai.extensions.langchain.chat_llm import LangChainChatInterface
from genai.extensions.langchain.embeddings import LangChainEmbeddingsInterface
Expand All @@ -8,6 +13,27 @@
to_langchain_template,
)


def _verify_langchain_version():
try:
langchain_version = get_package_version("langchain")
minimal_valid_version = parse_version("0.1.0")
current_version = parse_version(langchain_version)

if current_version < minimal_valid_version:
warnings.warn(
category=RuntimeWarning,
stacklevel=4,
message=f"You are using 'langchain' package version {current_version}. "
f"Please do upgrade now to version >= {minimal_valid_version}.",
)

except PackageNotFoundError:
pass


_verify_langchain_version()

__all__ = [
"LangChainInterface",
"LangChainChatInterface",
Expand Down

0 comments on commit db9f880

Please sign in to comment.