-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
[2.x] Upgrade to LangChain v0.3 and Pydantic v2 #1199
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dlqqq
force-pushed
the
v2-langchain-030
branch
from
January 14, 2025 21:19
90a37a9
to
049bd82
Compare
Addresses a Pydantic v2 deprecation warning, as `BaseModel.json()` is now deprecated in favor of `BaseModel.model_dump_json()`.
`BaseModel.dict()` is deprecated in favor of `BaseModel.model_dump()` in Pydantic v2.
dlqqq
force-pushed
the
v2-langchain-030
branch
from
January 14, 2025 21:20
049bd82
to
1fb1948
Compare
dlqqq
added a commit
to dlqqq/jupyter-ai
that referenced
this pull request
Jan 14, 2025
remove importliner from project initial upgrade to langchain~=0.3, pydantic~=2.0 default to `None` for all `Optional` fields explicitly fix history impl for Pydantic v2, fixes chat prefer `.model_dump_json()` over `.json()` Addresses a Pydantic v2 deprecation warning, as `BaseModel.json()` is now deprecated in favor of `BaseModel.model_dump_json()`. replace `.dict()` with `.model_dump()`. `BaseModel.dict()` is deprecated in favor of `BaseModel.model_dump()` in Pydantic v2. fix BaseProvider.server_settings fix OpenRouterProvider fix remaining unit tests address all Pydantic v1 deprecation warnings pre-commit fix mypy
Hey folks, our team of 5 engineers performed a 30 minute bug bash on this PR and didn't find any new bugs or regressions. Therefore, I will merge this PR into |
dlqqq
added a commit
that referenced
this pull request
Jan 15, 2025
* port PR #1199 to `main` branch, tracking v3 remove importliner from project initial upgrade to langchain~=0.3, pydantic~=2.0 default to `None` for all `Optional` fields explicitly fix history impl for Pydantic v2, fixes chat prefer `.model_dump_json()` over `.json()` Addresses a Pydantic v2 deprecation warning, as `BaseModel.json()` is now deprecated in favor of `BaseModel.model_dump_json()`. replace `.dict()` with `.model_dump()`. `BaseModel.dict()` is deprecated in favor of `BaseModel.model_dump()` in Pydantic v2. fix BaseProvider.server_settings fix OpenRouterProvider fix remaining unit tests address all Pydantic v1 deprecation warnings pre-commit fix mypy * remove stray pydantic v1 import
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
langchain>=0.3.0,<0.4.0
andpydantic>=2.0,<3.0
.import-linter
tool from the project, as it is no longer needed to block importing frompydantic
directly.cc @michaelchia @krassowski
Demo
Screen.Recording.2025-01-14.at.1.08.29.PM.mov
Notable Pydantic v2 changes
In
BaseModel
, the.dict()
and.json()
methods have been deprecated in favor of.model_dump()
and.model_dump_json()
respectively.All
Optional
fields no longer default to a value ofNone
in Pydantic v2. The default value ofNone
must be explicitly set in the model definition, otherwise an exception is raised at runtime.Optional
fields lacking a default:Optional\[[\w\[\]\s,]*\]\s*$
. I then added a default value ofNone
to each.It is no longer possible to implement an attribute from a parent class via a property while also inheriting from
BaseModel
. Upstream issue: Failure to override an inherited field with a computed field pydantic/pydantic#7250BaseModel
from theBoundedChatHistory
classes. They now just directly inherit fromBaseChatMessageHistory
.The
ModelMetaclass
is no longer available from a public module, and should be considered for internal use by Pydantic only. Therefore this PR no longer subclassesModelMetaclass
and reverts LangChain v0.1.0 #572.name
field on each provider to be resolved to...
(a literal Ellipses object). This is documented in Pinlangchain-core
dependency to prevent Settings UI crash #558.AFAIK, it is no longer possible to verify
server_settings: ClassVar[MappingProxyType]
is only set once. I've removed the associated test.ModelMetaclass
used by Pydantic internally (Prevent overridingserver_settings
on base provider class #825). However, in Pydantic v2, this metaclass is not exported by a public module, and therefore should not be subclassed.ClassVar
attributes are not treated as fields by Pydantic: no error when usingClassVar
andField
pydantic/pydantic#10169ClassVar
attributes as much as possible. The behavior of ClassVars isn't as well-defined as the behavior of other fields. For example, instead of using ClassVars to track globals, we should probably just store them as instance fields on singleton objects, e.g.ConfigManager
.Notable LangChain changes
Surprisingly, I didn't notice any which impact Jupyter AI. Reviewers, please let me know if I missed something.
For reviewers
Please test the application as much as possible. Both Pydantic & LangChain are used pervasively throughout the codebase, and both have introduced breaking changes since the previous version set.
What I've tested: