-
Notifications
You must be signed in to change notification settings - Fork 16.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
core[major]: Upgrade langchain-core to pydantic 2 #25986
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a4c3c26
upgrade
eyurtsev b69ad5d
lint pydantic extra
eyurtsev d52a962
Merge branch 'v0.3rc' into eugene/0.3rc_core
eyurtsev 988c912
update
eyurtsev d659b07
Merge branch 'eugene/0.3rc_core' of github.com:langchain-ai/langchain…
eyurtsev b7bca34
Update libs/core/langchain_core/language_models/base.py
eyurtsev 6f7c065
x
eyurtsev 7ec7822
Merge branch 'eugene/0.3rc_core' of github.com:langchain-ai/langchain…
eyurtsev c890fcd
ugh one more import
eyurtsev f39f196
x
eyurtsev 3ba41c2
Update libs/core/langchain_core/prompts/chat.py
eyurtsev ef50011
update comment
eyurtsev f6eb475
Merge branch 'eugene/0.3rc_core' of github.com:langchain-ai/langchain…
eyurtsev 6a20727
remove pydantic: ignore
eyurtsev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
Union, | ||
) | ||
|
||
from pydantic import BaseModel, ConfigDict, Field, validator | ||
from typing_extensions import TypeAlias, TypedDict | ||
|
||
from langchain_core._api import deprecated | ||
|
@@ -28,7 +29,6 @@ | |
get_buffer_string, | ||
) | ||
from langchain_core.prompt_values import PromptValue | ||
from langchain_core.pydantic_v1 import BaseModel, Field, validator | ||
from langchain_core.runnables import Runnable, RunnableSerializable | ||
from langchain_core.utils import get_pydantic_field_names | ||
|
||
|
@@ -113,7 +113,11 @@ class BaseLanguageModel( | |
|
||
Caching is not currently supported for streaming methods of models. | ||
""" | ||
verbose: bool = Field(default_factory=_get_verbosity) | ||
# Repr = False is consistent with pydantic 1 if verbose = False | ||
# We can relax this for pydantic 2? | ||
# TODO(Team): decide what to do here. | ||
eyurtsev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Modified just to get unit tests to pass. | ||
verbose: bool = Field(default_factory=_get_verbosity, exclude=True, repr=False) | ||
"""Whether to print out response text.""" | ||
callbacks: Callbacks = Field(default=None, exclude=True) | ||
"""Callbacks to add to the run trace.""" | ||
|
@@ -126,6 +130,10 @@ class BaseLanguageModel( | |
) | ||
"""Optional encoder to use for counting tokens.""" | ||
|
||
model_config = ConfigDict( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this new? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's required when using pydantic 2 since cache is an attribute on the chat model and the cache is not a base model |
||
arbitrary_types_allowed=True, | ||
) | ||
|
||
@validator("verbose", pre=True, always=True, allow_reuse=True) | ||
def set_verbose(cls, verbose: Optional[bool]) -> bool: | ||
"""If verbose is None, set it. | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update todo since we know we want to undo this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken the issue was that this ends up affecting caching behavior with verbose=False and verbose=None being cached differently -- i'll double check, but i updated a TODO(0.3) for us to resolve