From 03c63bfb84d2ce44abaf665aa53d2d5ce5881d10 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 16 Sep 2024 13:10:48 -0400 Subject: [PATCH 1/3] x --- docs/docs/versions/v0_3/index.mdx | 135 ++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 44 deletions(-) diff --git a/docs/docs/versions/v0_3/index.mdx b/docs/docs/versions/v0_3/index.mdx index 15e35ff78240e..e9dbe9142ace9 100644 --- a/docs/docs/versions/v0_3/index.mdx +++ b/docs/docs/versions/v0_3/index.mdx @@ -33,56 +33,56 @@ Any package that is now compatible with both `langchain-core` 0.2 and 0.3 had a ### Base packages -| Package | Latest | Recommended constraint | -| -------------------------------------- | ------- | -------------------------- | -| langchain | 0.3.0 | >=0.3,<0.4 | -| langchain-community | 0.3.0 | >=0.3,<0.4 | -| langchain-text-splitters | 0.3.0 | >=0.3,<0.4 | -| langchain-core | 0.3.0 | >=0.3,<0.4 | -| langchain-experimental | 0.3.0 | >=0.3,<0.4 | +| Package | Latest | Recommended constraint | +|--------------------------|--------|------------------------| +| langchain | 0.3.0 | >=0.3,<0.4 | +| langchain-community | 0.3.0 | >=0.3,<0.4 | +| langchain-text-splitters | 0.3.0 | >=0.3,<0.4 | +| langchain-core | 0.3.0 | >=0.3,<0.4 | +| langchain-experimental | 0.3.0 | >=0.3,<0.4 | ### Downstream packages -| Package | Latest | Recommended constraint | -| -------------------------------------- | ------- | -------------------------- | -| langgraph | 0.2.20 | >=0.2.20,<0.3 | -| langserve | 0.3.0 | >=0.3,<0.4 | +| Package | Latest | Recommended constraint | +|-----------|--------|------------------------| +| langgraph | 0.2.20 | >=0.2.20,<0.3 | +| langserve | 0.3.0 | >=0.3,<0.4 | ### Integration packages -| Package | Latest | Recommended constraint | -| -------------------------------------- | ------- | -------------------------- | -| langchain-ai21 | 0.2.0 | >=0.2,<0.3 | -| langchain-aws | 0.2.0 | >=0.2,<0.3 | -| langchain-anthropic | 0.2.0 | >=0.2,<0.3 | -| langchain-astradb | 0.4.1 | >=0.4.1,<0.5 | -| langchain-azure-dynamic-sessions | 0.2.0 | >=0.2,<0.3 | -| langchain-box | 0.2.0 | >=0.2,<0.3 | -| langchain-chroma | 0.1.4 | >=0.1.4,<0.2 | -| langchain-cohere | 0.2.0 | >=0.2,<0.3 | -| langchain-elasticsearch | 0.3.0 | >=0.3,<0.4 | -| langchain-exa | 0.2.0 | >=0.2,<0.3 | -| langchain-fireworks | 0.2.0 | >=0.2,<0.3 | -| langchain-groq | 0.2.0 | >=0.2,<0.3 | -| langchain-google-community | 2.0.0 | >=2,<3 | -| langchain-google-genai | 2.0.0 | >=2,<3 | -| langchain-google-vertexai | 2.0.0 | >=2,<3 | -| langchain-huggingface | 0.1.0 | >=0.1,<0.2 | -| langchain-milvus | 0.1.6 | >=0.1.6,<0.2 | -| langchain-mistralai | 0.2.0 | >=0.2,<0.3 | -| langchain-mongodb | 0.2.0 | >=0.2,<0.3 | -| langchain-nomic | 0.1.3 | >=0.1.3,<0.2 | -| langchain-ollama | 0.2.0 | >=0.2,<0.3 | -| langchain-openai | 0.2.0 | >=0.2,<0.3 | -| langchain-pinecone | 0.2.0 | >=0.2,<0.3 | -| langchain-postgres | 0.0.13 | >=0.0.13,<0.1 | -| langchain-prompty | 0.1.0 | >=0.1,<0.2 | -| langchain-redis | 0.1.0 | >=0.1,<0.2 | -| langchain-qdrant | 0.2.0 | >=0.2,<0.3 | -| langchain-together | 0.2.0 | >=0.2,<0.3 | -| langchain-unstructured | 0.1.4 | >=0.1.4,<0.2 | -| langchain-voyageai | 0.2.0 | >=0.2,<0.3 | -| langchain-weaviate | 0.1.0 | >=0.1,<0.2 | +| Package | Latest | Recommended constraint | +|----------------------------------|--------|------------------------| +| langchain-ai21 | 0.2.0 | >=0.2,<0.3 | +| langchain-aws | 0.2.0 | >=0.2,<0.3 | +| langchain-anthropic | 0.2.0 | >=0.2,<0.3 | +| langchain-astradb | 0.4.1 | >=0.4.1,<0.5 | +| langchain-azure-dynamic-sessions | 0.2.0 | >=0.2,<0.3 | +| langchain-box | 0.2.0 | >=0.2,<0.3 | +| langchain-chroma | 0.1.4 | >=0.1.4,<0.2 | +| langchain-cohere | 0.2.0 | >=0.2,<0.3 | +| langchain-elasticsearch | 0.3.0 | >=0.3,<0.4 | +| langchain-exa | 0.2.0 | >=0.2,<0.3 | +| langchain-fireworks | 0.2.0 | >=0.2,<0.3 | +| langchain-groq | 0.2.0 | >=0.2,<0.3 | +| langchain-google-community | 2.0.0 | >=2,<3 | +| langchain-google-genai | 2.0.0 | >=2,<3 | +| langchain-google-vertexai | 2.0.0 | >=2,<3 | +| langchain-huggingface | 0.1.0 | >=0.1,<0.2 | +| langchain-milvus | 0.1.6 | >=0.1.6,<0.2 | +| langchain-mistralai | 0.2.0 | >=0.2,<0.3 | +| langchain-mongodb | 0.2.0 | >=0.2,<0.3 | +| langchain-nomic | 0.1.3 | >=0.1.3,<0.2 | +| langchain-ollama | 0.2.0 | >=0.2,<0.3 | +| langchain-openai | 0.2.0 | >=0.2,<0.3 | +| langchain-pinecone | 0.2.0 | >=0.2,<0.3 | +| langchain-postgres | 0.0.13 | >=0.0.13,<0.1 | +| langchain-prompty | 0.1.0 | >=0.1,<0.2 | +| langchain-redis | 0.1.0 | >=0.1,<0.2 | +| langchain-qdrant | 0.2.0 | >=0.2,<0.3 | +| langchain-together | 0.2.0 | >=0.2,<0.3 | +| langchain-unstructured | 0.1.4 | >=0.1.4,<0.2 | +| langchain-voyageai | 0.2.0 | >=0.2,<0.3 | +| langchain-weaviate | 0.1.0 | >=0.1,<0.2 | Once you've updated to recent versions of the packages, you may need to address the following issues stemming from the internal switch from Pydantic v1 to Pydantic v2: @@ -185,6 +185,8 @@ CustomTool( When sub-classing from LangChain models, users may need to add relevant imports to the file and rebuild the model. +You can read more about `model_rebuild` [here](https://docs.pydantic.dev/latest/concepts/models/#rebuilding-model-schema). + ```python from langchain_core.output_parsers import BaseOutputParser @@ -205,3 +207,48 @@ class FooParser(BaseOutputParser): FooParser.model_rebuild() ``` + + +## Migrate using langchain-cli + +The `langchain-cli` can help migrate your code to new imports automatically. As of 0.0.31, the `langchain-cli` relies on [gritql](https://about.grit.io/) for applying code mods. + +## Installation + +```bash +pip install langchain-cli +langchain-cli --version # <-- Make sure the version is at least 0.0.31 +``` + +## Usage + +Given that the migration script is not perfect, you should make sure you have a backup of your code first (e.g., using version control like `git`). + +You will need to run the migration script **twice** as it only applies one import replacement per run. + +For example, say your code still uses `from langchain.chat_models import ChatOpenAI`: + +After the first run, you’ll get: `from langchain_community.chat_models import ChatOpenAI` +After the second run, you’ll get: `from langchain_openai import ChatOpenAI` + +```bash +# Run a first time +# Will replace from langchain.chat_models import ChatOpenAI +langchain-cli migrate --help [path to code] # Help +langchain-cli migrate [path to code] # Apply + +# Run a second time to apply more import replacements +langchain-cli migrate --diff [path to code] # Preview +langchain-cli migrate [path to code] # Apply +``` + +### Other options + +```bash +# See help menu +langchain-cli migrate --help +# Preview Changes without applying +langchain-cli migrate --diff [path to code] +# Approve changes interactively +langchain-cli migrate --interactive [path to code] +``` From d99e28b17ecb72cc0cf9276e74f19523ce724b58 Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 16 Sep 2024 13:55:44 -0400 Subject: [PATCH 2/3] Update docs/docs/versions/v0_3/index.mdx Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> --- docs/docs/versions/v0_3/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/versions/v0_3/index.mdx b/docs/docs/versions/v0_3/index.mdx index e9dbe9142ace9..e796f82377c18 100644 --- a/docs/docs/versions/v0_3/index.mdx +++ b/docs/docs/versions/v0_3/index.mdx @@ -216,7 +216,7 @@ The `langchain-cli` can help migrate your code to new imports automatically. As ## Installation ```bash -pip install langchain-cli +pip install -U langchain-cli langchain-cli --version # <-- Make sure the version is at least 0.0.31 ``` From c641baba39133e61c5efe77d2a54b516629789cb Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Mon, 16 Sep 2024 14:44:45 -0400 Subject: [PATCH 3/3] x --- docs/docs/versions/v0_3/index.mdx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/docs/versions/v0_3/index.mdx b/docs/docs/versions/v0_3/index.mdx index e796f82377c18..e84fb5997af55 100644 --- a/docs/docs/versions/v0_3/index.mdx +++ b/docs/docs/versions/v0_3/index.mdx @@ -23,7 +23,7 @@ The following features have been added during the development of 0.2.x: ## How to update your code -If you're using `langchain` / `langchain-community` / `langchain-core` 0.0 or 0.1, we recommend that you first [upgrade to 0.2](https://python.langchain.com/v0.2/docs/versions/v0_2/). The `langchain-cli` will help you to migrate many imports automatically. +If you're using `langchain` / `langchain-community` / `langchain-core` 0.0 or 0.1, we recommend that you first [upgrade to 0.2](https://python.langchain.com/v0.2/docs/versions/v0_2/). If you're using `langgraph`, upgrade to `langgraph>=0.2.20,<0.3`. This will work with either 0.2 or 0.3 versions of all the base packages. @@ -31,6 +31,11 @@ Here is a complete list of all packages that have been released and what we reco Any package that now requires `langchain-core` 0.3 had a minor version bump. Any package that is now compatible with both `langchain-core` 0.2 and 0.3 had a patch version bump. +You can use the `langchain-cli` to update deprecated imports automatically. +The CLI will handle updating deprecated imports that were introduced in LangChain 0.0.x and LangChain 0.1, as +well as updating the `langchain_core.pydantic_v1` and `langchain.pydantic_v1` imports. + + ### Base packages | Package | Latest | Recommended constraint | @@ -224,9 +229,12 @@ langchain-cli --version # <-- Make sure the version is at least 0.0.31 Given that the migration script is not perfect, you should make sure you have a backup of your code first (e.g., using version control like `git`). +The `langchain-cli` will handle the `langchain_core.pydantic_v1` deprecation introduced in LangChain 0.3 as well +as older deprecations (e.g.,`from langchain.chat_models import ChatOpenAI` which should be `from langchain_openai import ChatOpenAI`), + You will need to run the migration script **twice** as it only applies one import replacement per run. -For example, say your code still uses `from langchain.chat_models import ChatOpenAI`: +For example, say that your code is still using the old import `from langchain.chat_models import ChatOpenAI`: After the first run, you’ll get: `from langchain_community.chat_models import ChatOpenAI` After the second run, you’ll get: `from langchain_openai import ChatOpenAI`