-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Upgrade to Pydantic V2 #12265
Comments
🤖 That's great to hear! Thank you for your willingness to contribute to LangChain. Upgrading to Pydantic V2 sounds like a valuable improvement for the framework. Please go ahead and create a pull request with your proposed changes. The maintainers will review it and decide if it should be merged. Keep up the good work! 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. If you want to continue the conversation, start your reply with @dosu-bot. |
Langchain use v1, while Fastapi use v2. they can't work together. 😔 Hopefully v2 will be supported soon. |
I'm actually working on that upgrade now. Hopefully I can settle it in the next week. You'll still have to wait until the next release : / |
🤖 @baskaryan, I could use your expertise on this one. 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. If you want to continue the conversation, start your reply with @dosu-bot. |
Please reference the discussion here: #9337 LangChain is currently cross-compatible with both versions of pydantic. When using pydantic v2, langchain relies on the v1 namespace of pydantic v2. We cannot yet upgrade to v2 since that'll break LangChain to any users that are dependent on v1. v1 is more popular currently than v2 and is used by many of our users. FWIW: LangChain should be usable with fastapi and pydantic v2 -- as long as LangChain schema isn't used directly in the fast api request/responses (can clone the schema with pydantic v2 use that for fast api validation, and then internally convert to schema with pydantic v1 when working with LangChain). With that said, any work you can do to bring the code base to a state that will allow us to replace v1 models with v2 models will be appreciated. There's some automation that's available for this: https://github.com/pydantic/bump-pydantic, but it doesn't catch all cases and in a code base like LangChain there'll be a lot of manual work likely (we've got hundreds of pydantic classes). |
Can we use a variable to control which version is used? |
@mokeyish I'm not sure at which level you mean Users can control at the level fo the dependencies and install either pydantic v1 or pydantic v2. Everything will work as long as they don't only use v1 namespaced objects with langchain primitives; otherwise they can use pydantic v2 freely in their applications. If you mean to use a variable at the application level to configure LangChain to use the proper v2 namepace, that would be great, but I'm not sure how feasible, if you can come up with a solution let us know. LangChain is CI already runs with both pydantic v1 and v2 for unit tests so you can test out to see how well your solution works. As best as I can tell it's a bit of an all or nothing game with the pydantic migration -- I don't know that there's a safe way to upgrade some objects, but not others. :( |
@eyurtsev , I bump into this issue. I need to use |
@nikokaoja please follow the guidelines here: https://github.com/langchain-ai/langchain/blob/master/docs/docs/guides/pydantic_compatibility.md |
many thanks @eyurtsev ! it worked. |
Hi, @Luca-Blight, I'm helping the LangChain team manage their backlog and am marking this issue as stale. From the discussion, it seems that you were willing to contribute by creating a pull request to upgrade Pydantic from V1 to V2 for the Langchain project. There was ongoing discussion about the compatibility of Langchain with both versions of Pydantic, the potential impact on users, and the feasibility of using a variable to control the version used. You mentioned working on the upgrade and aiming to settle it in the next week. Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you for your understanding and contribution to the LangChain project. I'm dosu. |
Feature request
Langchain is currently using Pydantic V1, and I believe it would be good to upgrade this to V2
Motivation
V2 is far more performant than V1 because of the python-rust binding
Your contribution
I can create a PR here.
The text was updated successfully, but these errors were encountered: