langflow-ai / langflow

⛓️ Langflow is a dynamic graph where each node is an executable unit. Its modular and interactive design fosters rapid experimentation and prototyping, pushing hard on the limits of creativity.
http://www.langflow.org
MIT License
17.87k stars 2.68k forks source link

Update deprecated langchin output parser to maintained imports #1820

Open msmygit opened 2 weeks ago

msmygit commented 2 weeks ago

Describe the bug Currently within the dev branch, we are leveraging deprecated output parsers package from langchain. We need to update to use the community and supported version.

Browser and Version n/a

To Reproduce Steps to reproduce the behavior:

  1. Install and just start langflow run to see the deprecation warnings as below,
    % python -m langflow run --env-file ~/langflow/.env
    /Users/madhavan/.pyenv/versions/langflow/lib/python3.10/site-packages/langchain/_api/module_import.py:87: LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following:
    from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser
    warnings.warn(
    /Users/madhavan/.pyenv/versions/langflow/lib/python3.10/site-packages/langchain/_api/module_import.py:87: LangChainDeprecationWarning: Importing JsonSpec from langchain.tools.json is deprecated. Please replace the import with the following:
    from langchain_community.tools.json.tool import JsonSpec
    warnings.warn(
    Starting Langflow v1.0.0a29...
    ╭───────────────────────────────────────────────────╮
    │ Welcome to ⛓ Langflow                             │
    │                                                   │
    │                                                   │
    │ Collaborate, and contribute at our GitHub Repo 🚀 │
    │                                                   │
    │ Access http://127.0.0.1:7860                      │
    ╰───────────────────────────────────────────────────╯

Screenshots n/a

Additional context n/a

dosubot[bot] commented 2 weeks ago

To address the deprecation warnings and update your project to use the langchain_community package, follow these steps:

  1. Change Import Paths: Update your import statements to use langchain_community instead of langchain. For instance, replace:
from langchain.output_parsers import GuardrailsOutputParser

with:

from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser

And:

from langchain.tools.json import JsonSpec

with:

from langchain_community.tools.json.tool import JsonSpec
  1. Review Dynamic Imports: If your project dynamically imports modules, ensure the import strings reflect the new langchain_community package name.

  2. Handle Mixed Imports Carefully: If your project uses both langchain and langchain_community, update only the deprecated parts to langchain_community. Keep imports from langchain that don't have equivalents in the new package as they are.

  3. Test Your Application: After making these changes, thoroughly test your application to ensure all functionalities work as expected without introducing new issues.

By following these steps, you'll migrate away from deprecated langchain imports to the supported langchain_community package, aligning your project with the latest standards and avoiding deprecation warnings.

#### Details **Sources** - [src/backend/langflow/interface/tools/constants.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/langflow/interface/tools/constants.py) - [src/backend/base/langflow/interface/custom_lists.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/base/langflow/interface/custom_lists.py) - [src/backend/base/langflow/interface/importing/utils.py](https://github.com/logspace-ai/langflow/blob/dev/src/backend/base/langflow/interface/importing/utils.py) - [pyproject.toml](https://github.com/logspace-ai/langflow/blob/dev/pyproject.toml) - [src/frontend/run-tests.sh](https://github.com/logspace-ai/langflow/blob/dev/src/frontend/run-tests.sh) - [src/frontend/tests/end-to-end/filterEdge.spec.ts](https://github.com/logspace-ai/langflow/blob/dev/src/frontend/tests/end-to-end/filterEdge.spec.ts) - [scripts/update_dependencies.py](https://github.com/logspace-ai/langflow/blob/dev/scripts/update_dependencies.py)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

bchabros commented 1 week ago

@dosu

I have the same issue but this warning appear when I import PydanticOutputParser

from langchain.output_parsers import PydanticOutputParser

when I'tried change it on GuardrailsOutputParser it was completly different class.

Do you have any idea how to fix it this warning?

dongtandung2001 commented 1 week ago

@dosu I don't know why I did not import that package but still get the same warnning image

massi-ang commented 1 week ago

I am getting the same issue, and nowhere in my code I import the GuardrailsOutputParser package. This must be something imported by some other langchain module.

dongtandung2001 commented 1 week ago

I am getting the same issue, and nowhere in my code I import the GuardrailsOutputParser package. This must be something imported by some other langchain module.

I had to revert to this version to not get that warning image

ilude commented 1 week ago

Tried changing to @dongtandung2001 versions did not work for me.

Tried @dosu (bot) suggestion to use from langchain_community.output_parsers instead of what I have below also did not work:

from langchain_community.llms import Ollama
from langchain.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate
from langchain_core.messages import SystemMessage
from langchain.output_parsers import ResponseSchema, StructuredOutputParser

Guessing its something to do with the StructuredOutputParser import, but have not had time to dig any further into it.

ogabrielluiz commented 1 week ago

Hey all

This should be related to the some of the LangchainTypeCreators that are being fazed out soon.

llm-user commented 1 week ago

pip install langchain==0.1.19 solved it for me. This Stack Overflow discussion has some info.