mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 03:26:17 +00:00
cli[minor]: Fix bug to account for name changes (#20948)
* Fix bug to account for name changes / aliases * Generate migration list from langchain to langchain_core
This commit is contained in:
@@ -961,7 +961,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.callbacks.streamlit._InternalStreamlitCallbackHandler",
|
||||
"langchain_community.callbacks.streamlit.streamlit_callback_handler._InternalStreamlitCallbackHandler"
|
||||
"langchain_community.callbacks.streamlit.streamlit_callback_handler.StreamlitCallbackHandler"
|
||||
],
|
||||
[
|
||||
"langchain.callbacks.streamlit.mutable_expander.ChildType",
|
||||
@@ -1953,7 +1953,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.document_loaders.PagedPDFSplitter",
|
||||
"langchain_community.document_loaders.pdf.PagedPDFSplitter"
|
||||
"langchain_community.document_loaders.PyPDFLoader"
|
||||
],
|
||||
[
|
||||
"langchain.document_loaders.PlaywrightURLLoader",
|
||||
@@ -2069,7 +2069,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.document_loaders.TelegramChatLoader",
|
||||
"langchain_community.document_loaders.telegram.TelegramChatLoader"
|
||||
"langchain_community.document_loaders.TelegramChatLoader"
|
||||
],
|
||||
[
|
||||
"langchain.document_loaders.TensorflowDatasetLoader",
|
||||
@@ -3377,7 +3377,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.embeddings.SentenceTransformerEmbeddings",
|
||||
"langchain_community.embeddings.huggingface.SentenceTransformerEmbeddings"
|
||||
"langchain_community.embeddings.SentenceTransformerEmbeddings"
|
||||
],
|
||||
[
|
||||
"langchain.embeddings.GooglePalmEmbeddings",
|
||||
@@ -3673,7 +3673,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.embeddings.sentence_transformer.SentenceTransformerEmbeddings",
|
||||
"langchain_community.embeddings.huggingface.SentenceTransformerEmbeddings"
|
||||
"langchain_community.embeddings.SentenceTransformerEmbeddings"
|
||||
],
|
||||
[
|
||||
"langchain.embeddings.spacy_embeddings.SpacyEmbeddings",
|
||||
@@ -4905,7 +4905,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.requests.RequestsWrapper",
|
||||
"langchain_community.utilities.requests.RequestsWrapper"
|
||||
"langchain_community.utilities.TextRequestsWrapper"
|
||||
],
|
||||
[
|
||||
"langchain.requests.TextRequestsWrapper",
|
||||
@@ -7113,7 +7113,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.utilities.RequestsWrapper",
|
||||
"langchain_community.utilities.requests.RequestsWrapper"
|
||||
"langchain_community.utilities.TextRequestsWrapper"
|
||||
],
|
||||
[
|
||||
"langchain.utilities.SteamWebAPIWrapper",
|
||||
@@ -7409,7 +7409,7 @@
|
||||
],
|
||||
[
|
||||
"langchain.utilities.requests.RequestsWrapper",
|
||||
"langchain_community.utilities.requests.RequestsWrapper"
|
||||
"langchain_community.utilities.TextRequestsWrapper"
|
||||
],
|
||||
[
|
||||
"langchain.utilities.scenexplain.SceneXplainAPIWrapper",
|
File diff suppressed because it is too large
Load Diff
@@ -54,7 +54,7 @@ PARTNERS = [
|
||||
|
||||
def _load_migrations_from_fixtures() -> List[Tuple[str, str]]:
|
||||
"""Load migrations from fixtures."""
|
||||
paths: List[str] = PARTNERS + ["langchain.json"]
|
||||
paths: List[str] = PARTNERS + ["langchain_to_langchain_community.json"]
|
||||
data = []
|
||||
for path in paths:
|
||||
data.extend(_load_migrations_by_file(path))
|
||||
|
@@ -5,11 +5,11 @@ import pkgutil
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def generate_raw_migrations_to_community() -> List[Tuple[str, str]]:
|
||||
def generate_raw_migrations(
|
||||
from_package: str, to_package: str
|
||||
) -> List[Tuple[str, str]]:
|
||||
"""Scan the `langchain` package and generate migrations for all modules."""
|
||||
import langchain as package
|
||||
|
||||
to_package = "langchain_community"
|
||||
package = importlib.import_module(from_package)
|
||||
|
||||
items = []
|
||||
for importer, modname, ispkg in pkgutil.walk_packages(
|
||||
@@ -36,7 +36,9 @@ def generate_raw_migrations_to_community() -> List[Tuple[str, str]]:
|
||||
continue
|
||||
if obj and (inspect.isclass(obj) or inspect.isfunction(obj)):
|
||||
if obj.__module__.startswith(to_package):
|
||||
items.append((f"{modname}.{name}", f"{obj.__module__}.{name}"))
|
||||
items.append(
|
||||
(f"{modname}.{name}", f"{obj.__module__}.{obj.__name__}")
|
||||
)
|
||||
|
||||
# Iterate over all members of the module
|
||||
for name, obj in inspect.getmembers(module):
|
||||
@@ -44,12 +46,14 @@ def generate_raw_migrations_to_community() -> List[Tuple[str, str]]:
|
||||
if inspect.isclass(obj) or inspect.isfunction(obj):
|
||||
# Check if the module name of the obj starts with 'langchain_community'
|
||||
if obj.__module__.startswith(to_package):
|
||||
items.append((f"{modname}.{name}", f"{obj.__module__}.{name}"))
|
||||
items.append(
|
||||
(f"{modname}.{name}", f"{obj.__module__}.{obj.__name__}")
|
||||
)
|
||||
|
||||
return items
|
||||
|
||||
|
||||
def generate_top_level_imports_community() -> List[Tuple[str, str]]:
|
||||
def generate_top_level_imports(pkg: str) -> List[Tuple[str, str]]:
|
||||
"""This code will look at all the top level modules in langchain_community.
|
||||
|
||||
It'll attempt to import everything from each __init__ file
|
||||
@@ -73,7 +77,9 @@ def generate_top_level_imports_community() -> List[Tuple[str, str]]:
|
||||
to importing it from the top level namespaces
|
||||
(e.g., langchain_community.chat_models.XYZ)
|
||||
"""
|
||||
import langchain_community as package
|
||||
import importlib
|
||||
|
||||
package = importlib.import_module(pkg)
|
||||
|
||||
items = []
|
||||
# Only iterate through top-level modules/packages
|
||||
@@ -105,10 +111,12 @@ def generate_top_level_imports_community() -> List[Tuple[str, str]]:
|
||||
return items
|
||||
|
||||
|
||||
def generate_simplified_migrations() -> List[Tuple[str, str]]:
|
||||
def generate_simplified_migrations(
|
||||
from_package: str, to_package: str
|
||||
) -> List[Tuple[str, str]]:
|
||||
"""Get all the raw migrations, then simplify them if possible."""
|
||||
raw_migrations = generate_raw_migrations_to_community()
|
||||
top_level_simplifications = generate_top_level_imports_community()
|
||||
raw_migrations = generate_raw_migrations(from_package, to_package)
|
||||
top_level_simplifications = generate_top_level_imports(to_package)
|
||||
top_level_dict = {full: top_level for full, top_level in top_level_simplifications}
|
||||
simple_migrations = []
|
||||
for migration in raw_migrations:
|
Reference in New Issue
Block a user