mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-06 05:25:04 +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:
@@ -1,5 +1,6 @@
|
||||
"""Script to generate migrations for the migration script."""
|
||||
import json
|
||||
import pkgutil
|
||||
|
||||
import click
|
||||
|
||||
@@ -38,10 +39,39 @@ def partner(pkg: str, output: str) -> None:
|
||||
"""Generate migration scripts specifically for LangChain modules."""
|
||||
click.echo("Migration script for LangChain generated.")
|
||||
migrations = get_migrations_for_partner_package(pkg)
|
||||
output_name = f"partner_{pkg}.json" if output is None else output
|
||||
with open(output_name, "w") as f:
|
||||
f.write(json.dumps(migrations, indent=2, sort_keys=True))
|
||||
click.secho(f"LangChain migration script saved to {output_name}")
|
||||
# Run with python 3.9+
|
||||
output_name = f"{pkg.removeprefix('langchain_')}.json" if output is None else output
|
||||
if migrations:
|
||||
with open(output_name, "w") as f:
|
||||
f.write(json.dumps(migrations, indent=2, sort_keys=True))
|
||||
click.secho(f"LangChain migration script saved to {output_name}")
|
||||
else:
|
||||
click.secho(f"No migrations found for {pkg}", fg="yellow")
|
||||
|
||||
|
||||
@cli.command()
|
||||
def all_installed_partner_pkgs() -> None:
|
||||
"""Generate migration scripts for all LangChain modules."""
|
||||
# Will generate migrations for all pather packages.
|
||||
# Define as "langchain_<partner_name>".
|
||||
# First let's determine which packages are installed in the environment
|
||||
# and then generate migrations for them.
|
||||
langchain_pkgs = [
|
||||
name
|
||||
for _, name, _ in pkgutil.iter_modules()
|
||||
if name.startswith("langchain_")
|
||||
and name not in {"langchain_core", "langchain_cli", "langchain_community"}
|
||||
]
|
||||
for pkg in langchain_pkgs:
|
||||
migrations = get_migrations_for_partner_package(pkg)
|
||||
# Run with python 3.9+
|
||||
output_name = f"{pkg.removeprefix('langchain_')}.json"
|
||||
if migrations:
|
||||
with open(output_name, "w") as f:
|
||||
f.write(json.dumps(migrations, indent=2, sort_keys=True))
|
||||
click.secho(f"LangChain migration script saved to {output_name}")
|
||||
else:
|
||||
click.secho(f"No migrations found for {pkg}", fg="yellow")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -1 +0,0 @@
|
||||
[["langchain_community.embeddings.openai.OpenAIEmbeddings", "langchain_openai.embeddings.base.OpenAIEmbeddings"], ["langchain_community.embeddings.azure_openai.AzureOpenAIEmbeddings", "langchain_openai.embeddings.azure.AzureOpenAIEmbeddings"], ["langchain_community.chat_models.openai.ChatOpenAI", "langchain_openai.chat_models.base.ChatOpenAI"], ["langchain_community.chat_models.azure_openai.AzureChatOpenAI", "langchain_openai.chat_models.azure.AzureChatOpenAI"]]
|
Reference in New Issue
Block a user