langchain[patch]: Update deprecation warning (#21268)

Update deprecation warning
This commit is contained in:
Eugene Yurtsev 2024-05-03 15:31:29 -04:00 committed by GitHub
parent 23a05c3986
commit 335bd01e45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
import importlib
from typing import Any, Callable, Dict, Optional
from langchain_core._api import warn_deprecated
from langchain_core._api import internal, warn_deprecated
from langchain._api.interactive_env import is_interactive_env
@ -111,16 +111,22 @@ def create_importer(
and name in deprecated_lookups
and _should_deprecate_for_package(package)
):
# Depth 3:
# internal.py
# module_import.py
# Module in langchain that uses this function
# [calling code] whose frame we want to inspect.
if not internal.is_caller_internal(depth=3):
warn_deprecated(
since="0.1",
pending=False,
removal="0.4",
message=(
f"Importing {name} from {package} is deprecated. "
f"Please replace imports that look like:"
f"`from {package} import {name}`\n"
"with the following:\n "
f"from {new_module} import {name}"
f"Please replace deprecated imports:\n\n"
f">> from {package} import {name}\n\n"
"with new imports of:\n\n"
f">> from {new_module} import {name}\n"
),
)
return result
@ -134,16 +140,22 @@ def create_importer(
module = importlib.import_module(fallback_module)
result = getattr(module, name)
if not is_interactive_env() and _should_deprecate_for_package(package):
# Depth 3:
# internal.py
# module_import.py
# Module in langchain that uses this function
# [calling code] whose frame we want to inspect.
if not internal.is_caller_internal(depth=3):
warn_deprecated(
since="0.1",
pending=False,
removal="0.4",
message=(
f"Importing {name} from {package} is deprecated. "
f"Please replace imports that look like:"
f"`from {package} import {name}`\n"
"with the following:\n "
f"from {fallback_module} import {name}"
f"Please replace deprecated imports:\n\n"
f">> from {package} import {name}\n\n"
"with new imports of:\n\n"
f">> from {fallback_module} import {name}\n"
),
)
return result