mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-10 15:33:11 +00:00
cli[minor]: Improve partner migrations (#20938)
This auto generates partner migrations. At the moment the migration is from community -> partner. So one would need to run the migration script twice to go from langchain to partner.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import importlib
|
||||
from typing import List, Tuple
|
||||
|
||||
from langchain_core.documents import BaseDocumentCompressor, BaseDocumentTransformer
|
||||
from langchain_core.embeddings import Embeddings
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.retrievers import BaseRetriever
|
||||
@@ -11,6 +12,7 @@ from langchain_cli.namespaces.migrate.generate.utils import (
|
||||
COMMUNITY_PKG,
|
||||
find_subclasses_in_module,
|
||||
list_classes_by_package,
|
||||
list_init_imports_by_package,
|
||||
)
|
||||
|
||||
# PUBLIC API
|
||||
@@ -29,13 +31,24 @@ def get_migrations_for_partner_package(pkg_name: str) -> List[Tuple[str, str]]:
|
||||
"""
|
||||
package = importlib.import_module(pkg_name)
|
||||
classes_ = find_subclasses_in_module(
|
||||
package, [BaseLanguageModel, Embeddings, BaseRetriever, VectorStore]
|
||||
package,
|
||||
[
|
||||
BaseLanguageModel,
|
||||
Embeddings,
|
||||
BaseRetriever,
|
||||
VectorStore,
|
||||
BaseDocumentTransformer,
|
||||
BaseDocumentCompressor,
|
||||
],
|
||||
)
|
||||
community_classes = list_classes_by_package(str(COMMUNITY_PKG))
|
||||
imports_for_pkg = list_init_imports_by_package(str(COMMUNITY_PKG))
|
||||
|
||||
old_paths = community_classes + imports_for_pkg
|
||||
|
||||
migrations = [
|
||||
(f"{community_module}.{community_class}", f"{pkg_name}.{community_class}")
|
||||
for community_module, community_class in community_classes
|
||||
if community_class in classes_
|
||||
(f"{module}.{item}", f"{pkg_name}.{item}")
|
||||
for module, item in old_paths
|
||||
if item in classes_
|
||||
]
|
||||
return migrations
|
||||
|
Reference in New Issue
Block a user