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

Support for Pydantic v2 #6841

Closed
preritdas opened this issue Jun 27, 2023 · 30 comments
Closed

Support for Pydantic v2 #6841

preritdas opened this issue Jun 27, 2023 · 30 comments
Labels
03 enhancement Enhancement of existing functionality

Comments

@preritdas
Copy link
Contributor

Feature request

Currently, langchain 0.0.217 depends on pydantic<2 and >=1. Pydantic v2 is re-written in Rust and is between 5-50x faster than v1 depending on the use case. Given how much LangChain relies on Pydantic for both modeling and functional components, and given that FastAPI is now supporting (in beta) Pydantic v2, it'd be great to see LangChain handle a user-specified installation of Pydantic above v2.

The following is an example of what happens when a user specifies installing Pydantic above v2.

The conflict is caused by:
    The user requested pydantic==2.0b2
    fastapi 0.100.0b1 depends on pydantic!=1.8, !=1.8.1, <3.0.0 and >=1.7.4
    inflect 6.0.4 depends on pydantic>=1.9.1
    langchain 0.0.217 depends on pydantic<2 and >=1

Motivation

Pydantic v2 is re-written in Rust and is between 5-50x faster than v1 depending on the use case. Given how much LangChain relies on Pydantic for both modeling and functional components, and given that FastAPI is now supporting (in beta) Pydantic v2, it'd be great to see LangChain handle a user-specified installation of Pydantic above v2.

Your contribution

Yes! I'm currently opening just an issue to document my request, and because I'm fairly backlogged. But I have contributed to LangChain in the past and would love to write a pull request to facilitate this in full.

@dosubot dosubot bot added the 03 enhancement Enhancement of existing functionality label Jun 27, 2023
@dosubot
Copy link

dosubot bot commented Jun 27, 2023

Answer generated by a 🤖

Answer

Thank you for your interest in contributing to LangChain! We greatly appreciate your support.

It's fantastic to hear that you're willing to write a pull request to facilitate the support for Pydantic v2 in LangChain. Your contribution will be valuable in enhancing the framework's functionality and performance.

Please feel free to proceed with creating the pull request whenever you're ready. The maintainers will review it and determine if it aligns with the project's goals and requirements.

If you have any questions or need any assistance during the process, don't hesitate to ask. We're here to help. Happy coding!


This response is meant to be useful, save you time, and share context. 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.

@hidaris
Copy link

hidaris commented Jun 30, 2023

Yes, I just saw that pydantic v2 has been officially released. I am curious about the improvements and the extent of the upgrade in the context of langchain

@hidaris
Copy link

hidaris commented Jun 30, 2023

Related https://github.com/pydantic/bump-pydantic

@felixs8696
Copy link

+1 We are creating new projects with pydantic v2 and would like to use langchain as well

@ternaus
Copy link

ternaus commented Jul 6, 2023

Latest version of FastAPI uses pydantic 2.0

It would be great to use latest versions of langchain and pydantic

@timxieICN
Copy link

+1

2 similar comments
@matankley
Copy link

+1

@RichStone
Copy link

+1

@peter65374
Copy link

Second! Pydantic 2 is really great and lots of langchain's python developers are using FastAPI that bumps to Pydantic 2 recently.

@antonkulaga
Copy link

Guys, python-llama-cpp requires pydantic v2, when I install it langchain does not work anymore. Please, upgrade to prepare Pydantic 2

@aitoehigie
Copy link

In the meantime, before a release that supports Pydantic v2 is released, is there a walkaround?

@Gowee
Copy link

Gowee commented Jul 22, 2023

As suggested by Pydantic's README

Pydantic V2 also ships with the latest version of Pydantic V1 built in so that you can incrementally upgrade your code base and projects: from pydantic import v1 as pydantic_v1.

I suppose it is safe to upgrade to Pydantic v2 in no time by replacing all old usage of Pydantic with this so that to be compatible with other packages such as fastapi that has switched to Pydantic v2.

@Burgerniu
Copy link

+1

1 similar comment
@pstanisl
Copy link

+1

@mac-ema
Copy link

mac-ema commented Jul 26, 2023

+1 here too.

This is impossible to achieve because langchain depends on langsmith which is closed source (???) and depends on pydantic v1 as well.

@mohdhammad786
Copy link

I am facing this issue in my project please provide the support for pydantic 2 , i am stucked in dependency confict hell otherwise

@tasansal
Copy link
Contributor

tasansal commented Aug 1, 2023

+1 here.

@paryska99
Copy link

Bump. Would be good to have, when installing the updated llama-cpp-python it requires pydantic2 to use their server.

@fysp11
Copy link

fysp11 commented Aug 4, 2023

Bump

@aitoehigie
Copy link

aitoehigie commented Aug 4, 2023 via email

@bondzula
Copy link

bondzula commented Aug 9, 2023

bump :)

@bleschunov
Copy link

Guys!
I've created a solution https://github.com/bleschunov/langchain-with-pydantic-v2

@k1ng
Copy link

k1ng commented Aug 13, 2023

aiogram 3 also switched to Pydantic v2

@sjunepark
Copy link

+1

@afonio
Copy link

afonio commented Aug 14, 2023

It seems that langchain is not compatible with supabase v1.0.4(depends on gotrue~=1.0.3).

ERROR: Cannot install ... and supabase because these package versions have conflicting dependencies.

The conflict is caused by:
    fastapi 0.100.0 depends on pydantic!=1.8, !=1.8.1, !=2.0.0, !=2.0.1, <3.0.0 and >=1.7.4
    langchain 0.0.263 depends on pydantic<2 and >=1
    gotrue 1.0.3 depends on pydantic<3.0 and >=2.1

@bleschunov
Copy link

It seems that langchain is not compatible with supabase v1.0.4(depends on gotrue~=1.0.3).


ERROR: Cannot install ... and supabase because these package versions have conflicting dependencies.



The conflict is caused by:

    fastapi 0.100.0 depends on pydantic!=1.8, !=1.8.1, !=2.0.0, !=2.0.1, <3.0.0 and >=1.7.4

    langchain 0.0.263 depends on pydantic<2 and >=1

    gotrue 1.0.3 depends on pydantic<3.0 and >=2.1

It works with my solution https://github.com/bleschunov/langchain-with-pydantic-v2

@preritdas
Copy link
Contributor Author

Related #9123

@arpagon
Copy link

arpagon commented Aug 15, 2023

We must update to Pydantic 2.0 to maintain compatibility with several essential libraries and frameworks. For instance:

  • Supabase
  • llama-cpp-python
    • llamaV2
  • FastAPI > 0.100
  • Spacy

All of these require Pydantic 2.0 or higher, and I suspect the list will only grow longer.

We will get these libraries' latest features and improvements if we update them.

It's essential to assess the potential impact on the Langchain project and make an informed decision about the update.

#8330

@preritdas
Copy link
Contributor Author

Closing this issue as there's a whole migration planned by the maintainers. #9337

@dosubot dosubot bot mentioned this issue Aug 17, 2023
14 tasks
@baskaryan
Copy link
Collaborator

Hi all! As of langchain==0.0.267 the pydantic version is uncapped and we should largely be cross-compatible with pydantic v1 and v2. There are still some known pydantic v2 failure modes explained in #9337, and some potentially unknown failure modes.

We'd love to hear if the latest version unblocks your use cases or if you're still running into issues!

cc @arpagon, @preritdas, @felixs8696 @ternaus @paryska99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
03 enhancement Enhancement of existing functionality
Projects
None yet
Development

No branches or pull requests