langchain-community[major]: Upgrade community to pydantic 2 (#26011)

This PR upgrades langchain-community to pydantic 2.


* Most of this PR was auto-generated using code mods with gritql
(https://github.com/eyurtsev/migrate-pydantic/tree/main)
* Subsequently, some code was fixed manually due to accommodate
differences between pydantic 1 and 2

Breaking Changes:

- Use TEXTEMBED_API_KEY and TEXTEMBEB_API_URL for env variables for text
embed integrations:
cbea780492

Other changes:

- Added pydantic_settings as a required dependency for community. This
may be removed if we have enough time to convert the dependency into an
optional one.

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Harrison Chase
2024-09-05 11:07:10 -07:00
committed by GitHub
parent 1ad66e70dc
commit 8516a03a02
569 changed files with 2442 additions and 2330 deletions

View File

@@ -144,7 +144,7 @@ def deprecated(
_package: str = package,
) -> T:
"""Implementation of the decorator returned by `deprecated`."""
from langchain_core.utils.pydantic import FieldInfoV1
from langchain_core.utils.pydantic import FieldInfoV1, FieldInfoV2
def emit_warning() -> None:
"""Emit the warning."""
@@ -238,6 +238,25 @@ def deprecated(
exclude=obj.exclude,
),
)
elif isinstance(obj, FieldInfoV2):
wrapped = None
if not _obj_type:
_obj_type = "attribute"
if not _name:
raise ValueError(f"Field {obj} must have a name to be deprecated.")
old_doc = obj.description
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
return cast(
T,
FieldInfoV2(
default=obj.default,
default_factory=obj.default_factory,
description=new_doc,
alias=obj.alias,
exclude=obj.exclude,
),
)
elif isinstance(obj, property):
if not _obj_type: