Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] upgrading pydantic from v1 to v2 with solution #219

Closed
4 tasks done
Mai0313 opened this issue Mar 20, 2024 · 2 comments
Closed
4 tasks done

[Chore] upgrading pydantic from v1 to v2 with solution #219

Mai0313 opened this issue Mar 20, 2024 · 2 comments

Comments

@Mai0313
Copy link

Mai0313 commented Mar 20, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.

Example Code

This discussion is not related to any specific python code; this is more like a promotion or idea.

Error Message and Stack Trace (if applicable)

No response

Description

Intro

I am a software engineer at MediaTek, and my project involves using LangChain to address some of our challenges and to conduct research on topics related to LangChain. I believe a member of our team has already initiated contact with the vendor regarding the purchase of a LangSmith License.

Motivation

Today, I delved into the source code and discovered that this package heavily relies on Pydantic, specifically version 1. However, the OpenAI API is currently utilizing Pydantic==2.4.2 Ref, there is no reason we don't upgrade it as a developer.

Observation of current repository and needs

Here are some observations and understandings I have gathered:

  1. In langchain_core, langchain.pydantic_v1 is used solely for invoking pydantic.v1.
  2. There are significant differences between Pydantic v1 and v2, such as:
    • root_validator has been replaced by model_validator.
    • validator has been replaced by field_validator.
    • etc.

Question

Should we consider updating this module?
If so, it would be my honor to undertake this task.

Workflow

If I am to proceed, my approach would include:

  1. Replacing all instances of from langchain_core.pydantic_v1 import XXX with from pydantic import XXX within the langchain codebase.
  2. Making the necessary updates for Pydantic, including changes to model_validator, field_validator, etc.
  3. Keeping langchain_core.pydantic_v1 unchanged to avoid conflicts with other repositories, but issuing a deprecation warning to inform users and developers.

System Info

None

@Mai0313
Copy link
Author

Mai0313 commented Mar 20, 2024

This issue will be first discuss under this thread langchain-ai/langchain#19327 (reply in thread)

@hinthornw
Copy link
Contributor

This is a much larger change that we plan to do as a part of a future release.

LangChain is used by a large number of packages, many of whom still haven't upgraded to pydantic v2. We haven't wanted to break support for those users yet and wanted to give them time to upgrade before we fully break. We chose to create an interoperable layer to let you use langchain regardless of whether your environment has v1 or v2. Using v2 explicitly would break compatibility for those still on v1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants