mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 06:33:41 +00:00
Compare commits
4 Commits
mdrxy/fix-
...
eugene/sta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df32037497 | ||
|
|
f6cfc68bcc | ||
|
|
b766fb8681 | ||
|
|
c581e7172a |
@@ -16,6 +16,7 @@ from .beta_decorator import (
|
|||||||
)
|
)
|
||||||
from .deprecation import (
|
from .deprecation import (
|
||||||
LangChainDeprecationWarning,
|
LangChainDeprecationWarning,
|
||||||
|
caller_aware_warn,
|
||||||
deprecated,
|
deprecated,
|
||||||
suppress_langchain_deprecation_warning,
|
suppress_langchain_deprecation_warning,
|
||||||
surface_langchain_deprecation_warnings,
|
surface_langchain_deprecation_warnings,
|
||||||
@@ -35,4 +36,5 @@ __all__ = [
|
|||||||
"suppress_langchain_deprecation_warning",
|
"suppress_langchain_deprecation_warning",
|
||||||
"surface_langchain_deprecation_warnings",
|
"surface_langchain_deprecation_warnings",
|
||||||
"warn_deprecated",
|
"warn_deprecated",
|
||||||
|
"caller_aware_warn",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecati
|
|||||||
import contextlib
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Callable, Generator, Type, TypeVar
|
from typing import Any, Callable, Generator, Type, TypeVar
|
||||||
|
|
||||||
@@ -26,6 +27,15 @@ class LangChainDeprecationWarning(DeprecationWarning):
|
|||||||
class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
|
class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
|
||||||
"""A class for issuing deprecation warnings for LangChain users."""
|
"""A class for issuing deprecation warnings for LangChain users."""
|
||||||
|
|
||||||
|
SURFACE_INTERNAL_WARNINGS = (
|
||||||
|
os.environ.get("SURFACE_INTERNAL_WARNINGS", "false").lower() == "true"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_surface_internal_warnings() -> bool:
|
||||||
|
"""Mocked for testing."""
|
||||||
|
return SURFACE_INTERNAL_WARNINGS
|
||||||
|
|
||||||
|
|
||||||
# PUBLIC API
|
# PUBLIC API
|
||||||
|
|
||||||
@@ -379,8 +389,11 @@ def warn_deprecated(
|
|||||||
warning_cls = (
|
warning_cls = (
|
||||||
LangChainPendingDeprecationWarning if pending else LangChainDeprecationWarning
|
LangChainPendingDeprecationWarning if pending else LangChainDeprecationWarning
|
||||||
)
|
)
|
||||||
warning = warning_cls(message)
|
caller_aware_warn(
|
||||||
warnings.warn(warning, category=LangChainDeprecationWarning, stacklevel=2)
|
message,
|
||||||
|
category=warning_cls,
|
||||||
|
surface_internal_warnings=_get_surface_internal_warnings(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def surface_langchain_deprecation_warnings() -> None:
|
def surface_langchain_deprecation_warnings() -> None:
|
||||||
@@ -394,3 +407,18 @@ def surface_langchain_deprecation_warnings() -> None:
|
|||||||
"default",
|
"default",
|
||||||
category=LangChainDeprecationWarning,
|
category=LangChainDeprecationWarning,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def caller_aware_warn(
|
||||||
|
message: str,
|
||||||
|
*,
|
||||||
|
category: Type[Warning] = LangChainDeprecationWarning,
|
||||||
|
surface_internal_warnings: bool = False,
|
||||||
|
) -> None:
|
||||||
|
"""Warn deprecated"""
|
||||||
|
if surface_internal_warnings:
|
||||||
|
warnings.warn(message, category=category, stacklevel=2)
|
||||||
|
else:
|
||||||
|
if is_caller_internal(depth=2):
|
||||||
|
return
|
||||||
|
warnings.warn(message, category=category, stacklevel=2)
|
||||||
|
|||||||
@@ -1,13 +1,24 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import warnings
|
import warnings
|
||||||
|
from contextlib import contextmanager
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from langchain_core._api import deprecation
|
||||||
from langchain_core._api.deprecation import deprecated, warn_deprecated
|
from langchain_core._api.deprecation import deprecated, warn_deprecated
|
||||||
from langchain_core.pydantic_v1 import BaseModel
|
from langchain_core.pydantic_v1 import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def surface_internal_warnings() -> None:
|
||||||
|
"""Mock surface_langchain_deprecation_warnings."""
|
||||||
|
with patch.object(deprecation, "_get_surface_internal_warnings") as func:
|
||||||
|
func.return_value = True
|
||||||
|
yield func
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"kwargs, expected_message",
|
"kwargs, expected_message",
|
||||||
[
|
[
|
||||||
@@ -53,14 +64,26 @@ from langchain_core.pydantic_v1 import BaseModel
|
|||||||
)
|
)
|
||||||
def test_warn_deprecated(kwargs: Dict[str, Any], expected_message: str) -> None:
|
def test_warn_deprecated(kwargs: Dict[str, Any], expected_message: str) -> None:
|
||||||
"""Test warn deprecated."""
|
"""Test warn deprecated."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
|
warnings.simplefilter("always")
|
||||||
|
|
||||||
warn_deprecated(**kwargs)
|
warn_deprecated(**kwargs)
|
||||||
|
|
||||||
|
assert len(warning_list) == 1
|
||||||
|
warning = warning_list[0].message
|
||||||
|
assert str(warning) == expected_message
|
||||||
|
|
||||||
|
|
||||||
|
def test_internal_warnings_disabled() -> None:
|
||||||
|
"""Test that internal warnings are disabled properly"""
|
||||||
|
with patch.object(deprecation, "_get_surface_internal_warnings") as func:
|
||||||
|
func.return_value = False
|
||||||
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
|
warnings.simplefilter("always")
|
||||||
|
warn_deprecated("1.0.0", pending=True)
|
||||||
|
assert len(warning_list) == 0
|
||||||
|
|
||||||
assert len(warning_list) == 1
|
|
||||||
warning = warning_list[0].message
|
|
||||||
assert str(warning) == expected_message
|
|
||||||
|
|
||||||
|
|
||||||
def test_undefined_deprecation_schedule() -> None:
|
def test_undefined_deprecation_schedule() -> None:
|
||||||
@@ -117,143 +140,152 @@ class ClassWithDeprecatedMethods:
|
|||||||
|
|
||||||
def test_deprecated_function() -> None:
|
def test_deprecated_function() -> None:
|
||||||
"""Test deprecated function."""
|
"""Test deprecated function."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
assert deprecated_function() == "This is a deprecated function."
|
warnings.simplefilter("always")
|
||||||
assert len(warning_list) == 1
|
assert deprecated_function() == "This is a deprecated function."
|
||||||
warning = warning_list[0].message
|
assert len(warning_list) == 1
|
||||||
assert str(warning) == (
|
warning = warning_list[0].message
|
||||||
"The function `deprecated_function` was deprecated in LangChain 2.0.0 "
|
assert str(warning) == (
|
||||||
"and will be removed in 3.0.0"
|
"The function `deprecated_function` was deprecated in LangChain 2.0.0 "
|
||||||
)
|
"and will be removed in 3.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
doc = deprecated_function.__doc__
|
doc = deprecated_function.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
assert not inspect.iscoroutinefunction(deprecated_function)
|
assert not inspect.iscoroutinefunction(deprecated_function)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_deprecated_async_function() -> None:
|
async def test_deprecated_async_function() -> None:
|
||||||
"""Test deprecated async function."""
|
"""Test deprecated async function."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
assert (
|
warnings.simplefilter("always")
|
||||||
await deprecated_async_function() == "This is a deprecated async function."
|
assert (
|
||||||
)
|
await deprecated_async_function()
|
||||||
assert len(warning_list) == 1
|
== "This is a deprecated async function."
|
||||||
warning = warning_list[0].message
|
)
|
||||||
assert str(warning) == (
|
assert len(warning_list) == 1
|
||||||
"The function `deprecated_async_function` was deprecated "
|
warning = warning_list[0].message
|
||||||
"in LangChain 2.0.0 and will be removed in 3.0.0"
|
assert str(warning) == (
|
||||||
)
|
"The function `deprecated_async_function` was deprecated "
|
||||||
|
"in LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
doc = deprecated_function.__doc__
|
doc = deprecated_function.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
assert inspect.iscoroutinefunction(deprecated_async_function)
|
assert inspect.iscoroutinefunction(deprecated_async_function)
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_method() -> None:
|
def test_deprecated_method() -> None:
|
||||||
"""Test deprecated method."""
|
"""Test deprecated method."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
obj = ClassWithDeprecatedMethods()
|
warnings.simplefilter("always")
|
||||||
assert obj.deprecated_method() == "This is a deprecated method."
|
obj = ClassWithDeprecatedMethods()
|
||||||
assert len(warning_list) == 1
|
assert obj.deprecated_method() == "This is a deprecated method."
|
||||||
warning = warning_list[0].message
|
assert len(warning_list) == 1
|
||||||
assert str(warning) == (
|
warning = warning_list[0].message
|
||||||
"The function `deprecated_method` was deprecated in "
|
assert str(warning) == (
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"The function `deprecated_method` was deprecated in "
|
||||||
)
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
doc = obj.deprecated_method.__doc__
|
doc = obj.deprecated_method.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
assert not inspect.iscoroutinefunction(obj.deprecated_method)
|
assert not inspect.iscoroutinefunction(obj.deprecated_method)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_deprecated_async_method() -> None:
|
async def test_deprecated_async_method() -> None:
|
||||||
"""Test deprecated async method."""
|
"""Test deprecated async method."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
obj = ClassWithDeprecatedMethods()
|
warnings.simplefilter("always")
|
||||||
assert (
|
obj = ClassWithDeprecatedMethods()
|
||||||
await obj.deprecated_async_method() == "This is a deprecated async method."
|
assert (
|
||||||
)
|
await obj.deprecated_async_method()
|
||||||
assert len(warning_list) == 1
|
== "This is a deprecated async method."
|
||||||
warning = warning_list[0].message
|
)
|
||||||
assert str(warning) == (
|
assert len(warning_list) == 1
|
||||||
"The function `deprecated_async_method` was deprecated in "
|
warning = warning_list[0].message
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
assert str(warning) == (
|
||||||
)
|
"The function `deprecated_async_method` was deprecated in "
|
||||||
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
doc = obj.deprecated_method.__doc__
|
doc = obj.deprecated_method.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
assert inspect.iscoroutinefunction(obj.deprecated_async_method)
|
assert inspect.iscoroutinefunction(obj.deprecated_async_method)
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_classmethod() -> None:
|
def test_deprecated_classmethod() -> None:
|
||||||
"""Test deprecated classmethod."""
|
"""Test deprecated classmethod."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
ClassWithDeprecatedMethods.deprecated_classmethod()
|
warnings.simplefilter("always")
|
||||||
assert len(warning_list) == 1
|
ClassWithDeprecatedMethods.deprecated_classmethod()
|
||||||
warning = warning_list[0].message
|
assert len(warning_list) == 1
|
||||||
assert str(warning) == (
|
warning = warning_list[0].message
|
||||||
"The function `deprecated_classmethod` was deprecated in "
|
assert str(warning) == (
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"The function `deprecated_classmethod` was deprecated in "
|
||||||
)
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
doc = ClassWithDeprecatedMethods.deprecated_classmethod.__doc__
|
doc = ClassWithDeprecatedMethods.deprecated_classmethod.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_staticmethod() -> None:
|
def test_deprecated_staticmethod() -> None:
|
||||||
"""Test deprecated staticmethod."""
|
"""Test deprecated staticmethod."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
assert (
|
warnings.simplefilter("always")
|
||||||
ClassWithDeprecatedMethods.deprecated_staticmethod()
|
assert (
|
||||||
== "This is a deprecated staticmethod."
|
ClassWithDeprecatedMethods.deprecated_staticmethod()
|
||||||
)
|
== "This is a deprecated staticmethod."
|
||||||
assert len(warning_list) == 1
|
)
|
||||||
warning = warning_list[0].message
|
assert len(warning_list) == 1
|
||||||
|
warning = warning_list[0].message
|
||||||
|
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `deprecated_staticmethod` was deprecated in "
|
"The function `deprecated_staticmethod` was deprecated in "
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
)
|
)
|
||||||
doc = ClassWithDeprecatedMethods.deprecated_staticmethod.__doc__
|
doc = ClassWithDeprecatedMethods.deprecated_staticmethod.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_property() -> None:
|
def test_deprecated_property() -> None:
|
||||||
"""Test deprecated staticmethod."""
|
"""Test deprecated staticmethod."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
|
warnings.simplefilter("always")
|
||||||
|
|
||||||
obj = ClassWithDeprecatedMethods()
|
obj = ClassWithDeprecatedMethods()
|
||||||
assert obj.deprecated_property == "This is a deprecated property."
|
assert obj.deprecated_property == "This is a deprecated property."
|
||||||
|
|
||||||
assert len(warning_list) == 1
|
assert len(warning_list) == 1
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
|
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `deprecated_property` was deprecated in "
|
"The function `deprecated_property` was deprecated in "
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
)
|
)
|
||||||
doc = ClassWithDeprecatedMethods.deprecated_property.__doc__
|
doc = ClassWithDeprecatedMethods.deprecated_property.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|
||||||
|
|
||||||
def test_whole_class_deprecation() -> None:
|
def test_whole_class_deprecation() -> None:
|
||||||
@@ -271,27 +303,28 @@ def test_whole_class_deprecation() -> None:
|
|||||||
"""original doc"""
|
"""original doc"""
|
||||||
return "This is a deprecated method."
|
return "This is a deprecated method."
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
|
warnings.simplefilter("always")
|
||||||
|
|
||||||
obj = DeprecatedClass()
|
obj = DeprecatedClass()
|
||||||
assert obj.deprecated_method() == "This is a deprecated method."
|
assert obj.deprecated_method() == "This is a deprecated method."
|
||||||
|
|
||||||
assert len(warning_list) == 2
|
assert len(warning_list) == 2
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The class `tests.unit_tests._api.test_deprecation.DeprecatedClass` was "
|
"The class `tests.unit_tests._api.test_deprecation.DeprecatedClass` was "
|
||||||
"deprecated in tests 2.0.0 and will be removed in 3.0.0"
|
"deprecated in tests 2.0.0 and will be removed in 3.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
warning = warning_list[1].message
|
warning = warning_list[1].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `deprecated_method` was deprecated in "
|
"The function `deprecated_method` was deprecated in "
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
)
|
)
|
||||||
# [*Deprecated*] should be inserted only once:
|
# [*Deprecated*] should be inserted only once:
|
||||||
if obj.__doc__ is not None:
|
if obj.__doc__ is not None:
|
||||||
assert obj.__doc__.count("[*Deprecated*]") == 1
|
assert obj.__doc__.count("[*Deprecated*]") == 1
|
||||||
|
|
||||||
|
|
||||||
def test_whole_class_inherited_deprecation() -> None:
|
def test_whole_class_inherited_deprecation() -> None:
|
||||||
@@ -326,51 +359,52 @@ def test_whole_class_inherited_deprecation() -> None:
|
|||||||
"""original doc"""
|
"""original doc"""
|
||||||
return "This is a deprecated method."
|
return "This is a deprecated method."
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
|
warnings.simplefilter("always")
|
||||||
|
|
||||||
obj = DeprecatedClass()
|
obj = DeprecatedClass()
|
||||||
assert obj.deprecated_method() == "This is a deprecated method."
|
assert obj.deprecated_method() == "This is a deprecated method."
|
||||||
|
|
||||||
assert len(warning_list) == 2
|
assert len(warning_list) == 2
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The class `tests.unit_tests._api.test_deprecation.DeprecatedClass` was "
|
"The class `tests.unit_tests._api.test_deprecation.DeprecatedClass` was "
|
||||||
"deprecated in tests 2.0.0 and will be removed in 3.0.0"
|
"deprecated in tests 2.0.0 and will be removed in 3.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
warning = warning_list[1].message
|
warning = warning_list[1].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `deprecated_method` was deprecated in "
|
"The function `deprecated_method` was deprecated in "
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
)
|
)
|
||||||
# if [*Deprecated*] was inserted only once:
|
# if [*Deprecated*] was inserted only once:
|
||||||
if obj.__doc__ is not None:
|
if obj.__doc__ is not None:
|
||||||
assert obj.__doc__.count("[*Deprecated*]") == 1
|
assert obj.__doc__.count("[*Deprecated*]") == 1
|
||||||
|
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
warnings.simplefilter("always")
|
warnings.simplefilter("always")
|
||||||
|
|
||||||
obj = InheritedDeprecatedClass()
|
obj = InheritedDeprecatedClass()
|
||||||
assert obj.deprecated_method() == "This is a deprecated method."
|
assert obj.deprecated_method() == "This is a deprecated method."
|
||||||
|
|
||||||
assert len(warning_list) == 2
|
assert len(warning_list) == 2
|
||||||
warning = warning_list[0].message
|
warning = warning_list[0].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The class "
|
"The class "
|
||||||
"`tests.unit_tests._api.test_deprecation.InheritedDeprecatedClass` "
|
"`tests.unit_tests._api.test_deprecation.InheritedDeprecatedClass` "
|
||||||
"was deprecated in tests 2.2.0 and will be removed in 3.2.0"
|
"was deprecated in tests 2.2.0 and will be removed in 3.2.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
warning = warning_list[1].message
|
warning = warning_list[1].message
|
||||||
assert str(warning) == (
|
assert str(warning) == (
|
||||||
"The function `deprecated_method` was deprecated in "
|
"The function `deprecated_method` was deprecated in "
|
||||||
"LangChain 2.2.0 and will be removed in 3.2.0"
|
"LangChain 2.2.0 and will be removed in 3.2.0"
|
||||||
)
|
)
|
||||||
# if [*Deprecated*] was inserted only once:
|
# if [*Deprecated*] was inserted only once:
|
||||||
if obj.__doc__ is not None:
|
if obj.__doc__ is not None:
|
||||||
assert obj.__doc__.count("[*Deprecated*]") == 1
|
assert obj.__doc__.count("[*Deprecated*]") == 1
|
||||||
assert "[*Deprecated*] Inherited deprecated class." in obj.__doc__
|
assert "[*Deprecated*] Inherited deprecated class." in obj.__doc__
|
||||||
|
|
||||||
|
|
||||||
# Tests with pydantic models
|
# Tests with pydantic models
|
||||||
@@ -383,17 +417,18 @@ class MyModel(BaseModel):
|
|||||||
|
|
||||||
def test_deprecated_method_pydantic() -> None:
|
def test_deprecated_method_pydantic() -> None:
|
||||||
"""Test deprecated method."""
|
"""Test deprecated method."""
|
||||||
with warnings.catch_warnings(record=True) as warning_list:
|
with surface_internal_warnings():
|
||||||
warnings.simplefilter("always")
|
with warnings.catch_warnings(record=True) as warning_list:
|
||||||
obj = MyModel()
|
warnings.simplefilter("always")
|
||||||
assert obj.deprecated_method() == "This is a deprecated method."
|
obj = MyModel()
|
||||||
assert len(warning_list) == 1
|
assert obj.deprecated_method() == "This is a deprecated method."
|
||||||
warning = warning_list[0].message
|
assert len(warning_list) == 1
|
||||||
assert str(warning) == (
|
warning = warning_list[0].message
|
||||||
"The function `deprecated_method` was deprecated in "
|
assert str(warning) == (
|
||||||
"LangChain 2.0.0 and will be removed in 3.0.0"
|
"The function `deprecated_method` was deprecated in "
|
||||||
)
|
"LangChain 2.0.0 and will be removed in 3.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
doc = obj.deprecated_method.__doc__
|
doc = obj.deprecated_method.__doc__
|
||||||
assert isinstance(doc, str)
|
assert isinstance(doc, str)
|
||||||
assert doc.startswith("[*Deprecated*] original doc")
|
assert doc.startswith("[*Deprecated*] original doc")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ EXPECTED_ALL = [
|
|||||||
"warn_deprecated",
|
"warn_deprecated",
|
||||||
"as_import_path",
|
"as_import_path",
|
||||||
"get_relative_path",
|
"get_relative_path",
|
||||||
|
"caller_aware_warn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -246,15 +246,14 @@ def test_chat_valid_infer_variables() -> None:
|
|||||||
|
|
||||||
def test_chat_from_role_strings() -> None:
|
def test_chat_from_role_strings() -> None:
|
||||||
"""Test instantiation of chat template from role strings."""
|
"""Test instantiation of chat template from role strings."""
|
||||||
with pytest.warns(LangChainPendingDeprecationWarning):
|
template = ChatPromptTemplate.from_role_strings(
|
||||||
template = ChatPromptTemplate.from_role_strings(
|
[
|
||||||
[
|
("system", "You are a bot."),
|
||||||
("system", "You are a bot."),
|
("assistant", "hello!"),
|
||||||
("assistant", "hello!"),
|
("human", "{question}"),
|
||||||
("human", "{question}"),
|
("other", "{quack}"),
|
||||||
("other", "{quack}"),
|
]
|
||||||
]
|
)
|
||||||
)
|
|
||||||
|
|
||||||
messages = template.format_messages(question="How are you?", quack="duck")
|
messages = template.format_messages(question="How are you?", quack="duck")
|
||||||
assert messages == [
|
assert messages == [
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
# ruff: noqa: E402
|
# ruff: noqa: E402
|
||||||
"""Main entrypoint into package."""
|
"""Main entrypoint into package."""
|
||||||
import warnings
|
|
||||||
from importlib import metadata
|
from importlib import metadata
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from langchain_core._api.deprecation import surface_langchain_deprecation_warnings
|
from langchain_core._api.deprecation import (
|
||||||
|
caller_aware_warn,
|
||||||
|
surface_langchain_deprecation_warnings,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
__version__ = metadata.version(__package__)
|
__version__ = metadata.version(__package__)
|
||||||
@@ -26,13 +28,13 @@ def _warn_on_import(name: str, replacement: Optional[str] = None) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if replacement:
|
if replacement:
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
f"Importing {name} from langchain root module is no longer supported. "
|
f"Importing {name} from langchain root module is no longer supported. "
|
||||||
f"Please use {replacement} instead."
|
f"Please use {replacement} instead.",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
f"Importing {name} from langchain root module is no longer supported."
|
f"Importing {name} from langchain root module is no longer supported.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ whether permissions of the given toolkit are appropriate for the application.
|
|||||||
|
|
||||||
See [Security](https://python.langchain.com/docs/security) for more information.
|
See [Security](https://python.langchain.com/docs/security) for more information.
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
from langchain_core._api.path import as_import_path
|
from langchain_core._api.path import as_import_path
|
||||||
|
|
||||||
from langchain.agents.agent_toolkits.conversational_retrieval.openai_functions import (
|
from langchain.agents.agent_toolkits.conversational_retrieval.openai_functions import (
|
||||||
@@ -61,13 +60,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing this agent toolkit from langchain is deprecated. Importing it "
|
"Importing this agent toolkit from langchain is deprecated. Importing it "
|
||||||
"from langchain will no longer be supported as of langchain==0.2.0. "
|
"from langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.agent_toolkits import {name}`.\n\n"
|
f"`from langchain_community.agent_toolkits import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(agent_toolkits, name)
|
return getattr(agent_toolkits, name)
|
||||||
|
|||||||
@@ -6,10 +6,9 @@
|
|||||||
|
|
||||||
BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler
|
BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
StdOutCallbackHandler,
|
StdOutCallbackHandler,
|
||||||
StreamingStdOutCallbackHandler,
|
StreamingStdOutCallbackHandler,
|
||||||
@@ -34,15 +33,13 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing this callback from langchain is deprecated. Importing it from "
|
"Importing this callback from langchain is deprecated. Importing it from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.callbacks import {name}`.\n\n"
|
f"`from langchain_community.callbacks import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(callbacks, name)
|
return getattr(callbacks, name)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,8 @@ an interface where "chat messages" are the inputs and outputs.
|
|||||||
|
|
||||||
AIMessage, BaseMessage, HumanMessage
|
AIMessage, BaseMessage, HumanMessage
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
import warnings
|
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
@@ -28,13 +27,12 @@ def __getattr__(name: str) -> None:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing chat models from langchain is deprecated. Importing from "
|
"Importing chat models from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.chat_models import {name}`.\n\n"
|
f"`from langchain_community.chat_models import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(chat_models, name)
|
return getattr(chat_models, name)
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ The **Docstore** is a simplified version of the Document Loader.
|
|||||||
|
|
||||||
Document, AddableMixin
|
Document, AddableMixin
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
@@ -27,13 +26,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing docstores from langchain is deprecated. Importing from "
|
"Importing docstores from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.docstore import {name}`.\n\n"
|
f"`from langchain_community.docstore import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(docstore, name)
|
return getattr(docstore, name)
|
||||||
|
|||||||
@@ -14,10 +14,9 @@
|
|||||||
|
|
||||||
Document, <name>TextSplitter
|
Document, <name>TextSplitter
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
@@ -33,17 +32,16 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing document loaders from langchain is deprecated. Importing from "
|
"Importing document loaders from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.document_loaders import {name}`.\n\n"
|
f"`from langchain_community.document_loaders import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if name in _old_to_new_name:
|
if name in _old_to_new_name:
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
f"Using legacy class name {name}, use {_old_to_new_name[name]} instead."
|
f"Using legacy class name {name}, use {_old_to_new_name[name]} instead."
|
||||||
)
|
)
|
||||||
name = _old_to_new_name[name]
|
name = _old_to_new_name[name]
|
||||||
|
|||||||
@@ -14,10 +14,9 @@
|
|||||||
|
|
||||||
Document
|
Document
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
@@ -27,13 +26,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing document transformers from langchain is deprecated. Importing "
|
"Importing document transformers from langchain is deprecated. Importing "
|
||||||
"from langchain will no longer be supported as of langchain==0.2.0. "
|
"from langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.document_transformers import {name}`.\n\n"
|
f"`from langchain_community.document_transformers import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(document_transformers, name)
|
return getattr(document_transformers, name)
|
||||||
|
|||||||
@@ -12,10 +12,9 @@ from different APIs and services.
|
|||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.embeddings.cache import CacheBackedEmbeddings
|
from langchain.embeddings.cache import CacheBackedEmbeddings
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
@@ -26,13 +25,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing embeddings from langchain is deprecated. Importing from "
|
"Importing embeddings from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.embeddings import {name}`.\n\n"
|
f"`from langchain_community.embeddings import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(embeddings, name)
|
return getattr(embeddings, name)
|
||||||
|
|||||||
@@ -17,10 +17,9 @@ access to the large language model (**LLM**) APIs and services.
|
|||||||
CallbackManager, AsyncCallbackManager,
|
CallbackManager, AsyncCallbackManager,
|
||||||
AIMessage, BaseMessage
|
AIMessage, BaseMessage
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
import warnings
|
|
||||||
from typing import Any, Callable, Dict, Type
|
from typing import Any, Callable, Dict, Type
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
from langchain_core.language_models.llms import BaseLLM
|
from langchain_core.language_models.llms import BaseLLM
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
@@ -545,13 +544,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing LLMs from langchain is deprecated. Importing from "
|
"Importing LLMs from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.llms import {name}`.\n\n"
|
f"`from langchain_community.llms import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if name == "type_to_cls_dict":
|
if name == "type_to_cls_dict":
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
@@ -11,15 +10,13 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing chat message histories from langchain is deprecated. Importing "
|
"Importing chat message histories from langchain is deprecated. Importing "
|
||||||
"from langchain will no longer be supported as of langchain==0.2.0. "
|
"from langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.chat_message_histories import {name}`.\n\n"
|
f"`from langchain_community.chat_message_histories import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(chat_message_histories, name)
|
return getattr(chat_message_histories, name)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,9 @@ the backbone of a retriever, but there are other types of retrievers as well.
|
|||||||
Document, Serializable, Callbacks,
|
Document, Serializable, Callbacks,
|
||||||
CallbackManagerForRetrieverRun, AsyncCallbackManagerForRetrieverRun
|
CallbackManagerForRetrieverRun, AsyncCallbackManagerForRetrieverRun
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
|
from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
|
||||||
from langchain.retrievers.ensemble import EnsembleRetriever
|
from langchain.retrievers.ensemble import EnsembleRetriever
|
||||||
@@ -43,13 +42,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing this retriever from langchain is deprecated. Importing it from "
|
"Importing this retriever from langchain is deprecated. Importing it from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.retrievers import {name}`.\n\n"
|
f"`from langchain_community.retrievers import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(retrievers, name)
|
return getattr(retrievers, name)
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ to a simple key-value interface.
|
|||||||
|
|
||||||
The primary goal of these storages is to support implementation of caching.
|
The primary goal of these storages is to support implementation of caching.
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.storage._lc_store import create_kv_docstore, create_lc_store
|
from langchain.storage._lc_store import create_kv_docstore, create_lc_store
|
||||||
from langchain.storage.encoder_backed import EncoderBackedStore
|
from langchain.storage.encoder_backed import EncoderBackedStore
|
||||||
@@ -22,13 +21,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing stores from langchain is deprecated. Importing from "
|
"Importing stores from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.storage import {name}`.\n\n"
|
f"`from langchain_community.storage import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(storage, name)
|
return getattr(storage, name)
|
||||||
|
|||||||
@@ -16,10 +16,9 @@ tool for the job.
|
|||||||
|
|
||||||
CallbackManagerForToolRun, AsyncCallbackManagerForToolRun
|
CallbackManagerForToolRun, AsyncCallbackManagerForToolRun
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
from langchain_core.tools import BaseTool, StructuredTool, Tool, tool
|
from langchain_core.tools import BaseTool, StructuredTool, Tool, tool
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
@@ -60,14 +59,13 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing tools from langchain is deprecated. Importing from "
|
"Importing tools from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.tools import {name}`.\n\n"
|
f"`from langchain_community.tools import {name}`.\n\n"
|
||||||
"To install langchain-community run "
|
"To install langchain-community run "
|
||||||
"`pip install -U langchain-community`.",
|
"`pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(tools, name)
|
return getattr(tools, name)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
Other LangChain classes use **Utilities** to interact with third-part systems
|
Other LangChain classes use **Utilities** to interact with third-part systems
|
||||||
and packages.
|
and packages.
|
||||||
"""
|
"""
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_community.utilities.requests import (
|
from langchain_community.utilities.requests import (
|
||||||
@@ -11,7 +10,7 @@ from langchain_community.utilities.requests import (
|
|||||||
RequestsWrapper,
|
RequestsWrapper,
|
||||||
TextRequestsWrapper,
|
TextRequestsWrapper,
|
||||||
)
|
)
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
|
|
||||||
@@ -21,13 +20,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing this utility from langchain is deprecated. Importing it from "
|
"Importing this utility from langchain is deprecated. Importing it from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.utilities import {name}`.\n\n"
|
f"`from langchain_community.utilities import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(utilities, name)
|
return getattr(utilities, name)
|
||||||
|
|||||||
@@ -18,10 +18,9 @@ and retrieve the data that are 'most similar' to the embedded query.
|
|||||||
|
|
||||||
Embeddings, Document
|
Embeddings, Document
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
import warnings
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from langchain_core._api import LangChainDeprecationWarning
|
from langchain_core._api import caller_aware_warn
|
||||||
from langchain_core.vectorstores import VectorStore
|
from langchain_core.vectorstores import VectorStore
|
||||||
|
|
||||||
from langchain.utils.interactive_env import is_interactive_env
|
from langchain.utils.interactive_env import is_interactive_env
|
||||||
@@ -32,13 +31,12 @@ def __getattr__(name: str) -> Any:
|
|||||||
|
|
||||||
# If not in interactive env, raise warning.
|
# If not in interactive env, raise warning.
|
||||||
if not is_interactive_env():
|
if not is_interactive_env():
|
||||||
warnings.warn(
|
caller_aware_warn(
|
||||||
"Importing vector stores from langchain is deprecated. Importing from "
|
"Importing vector stores from langchain is deprecated. Importing from "
|
||||||
"langchain will no longer be supported as of langchain==0.2.0. "
|
"langchain will no longer be supported as of langchain==0.2.0. "
|
||||||
"Please import from langchain-community instead:\n\n"
|
"Please import from langchain-community instead:\n\n"
|
||||||
f"`from langchain_community.vectorstores import {name}`.\n\n"
|
f"`from langchain_community.vectorstores import {name}`.\n\n"
|
||||||
"To install langchain-community run `pip install -U langchain-community`.",
|
"To install langchain-community run `pip install -U langchain-community`.",
|
||||||
category=LangChainDeprecationWarning,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return getattr(vectorstores, name)
|
return getattr(vectorstores, name)
|
||||||
|
|||||||
Reference in New Issue
Block a user