mirror of https://github.com/hwchase17/langchain
langchain[patch]: Migrate more code in utils to use optional langchain import (#21166)
Moving is interactive util to avoid circular depspull/21172/head
parent
23fdd320bc
commit
94a838740e
@ -1,7 +1,32 @@
|
|||||||
from langchain_community.utils.math import (
|
from typing import TYPE_CHECKING, Any
|
||||||
Matrix,
|
|
||||||
cosine_similarity,
|
|
||||||
cosine_similarity_top_k,
|
|
||||||
)
|
|
||||||
|
|
||||||
__all__ = ["Matrix", "cosine_similarity", "cosine_similarity_top_k"]
|
from langchain._api import create_importer
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from langchain_community.utils.math import (
|
||||||
|
cosine_similarity,
|
||||||
|
cosine_similarity_top_k,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a way to dynamically look up deprecated imports.
|
||||||
|
# Used to consolidate logic for raising deprecation warnings and
|
||||||
|
# handling optional imports.
|
||||||
|
# Not marked as deprecated since we may want to move the functionality
|
||||||
|
# into langchain as long as we're OK with numpy as the dependency.
|
||||||
|
_MODULE_LOOKUP = {
|
||||||
|
"cosine_similarity": "langchain_community.utils.math",
|
||||||
|
"cosine_similarity_top_k": "langchain_community.utils.math",
|
||||||
|
}
|
||||||
|
|
||||||
|
_import_attribute = create_importer(__package__, module_lookup=_MODULE_LOOKUP)
|
||||||
|
|
||||||
|
|
||||||
|
def __getattr__(name: str) -> Any:
|
||||||
|
"""Look up attributes dynamically."""
|
||||||
|
return _import_attribute(name)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"cosine_similarity",
|
||||||
|
"cosine_similarity_top_k",
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue