mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 08:33:49 +00:00
core[patch]: support Field deprecation (#25004)

This commit is contained in:
parent
803eba3163
commit
df99b832a7
@ -133,6 +133,7 @@ def deprecated(
|
|||||||
_package: str = package,
|
_package: str = package,
|
||||||
) -> T:
|
) -> T:
|
||||||
"""Implementation of the decorator returned by `deprecated`."""
|
"""Implementation of the decorator returned by `deprecated`."""
|
||||||
|
from pydantic.v1.fields import FieldInfo # pydantic: ignore
|
||||||
|
|
||||||
def emit_warning() -> None:
|
def emit_warning() -> None:
|
||||||
"""Emit the warning."""
|
"""Emit the warning."""
|
||||||
@ -207,6 +208,25 @@ def deprecated(
|
|||||||
)
|
)
|
||||||
return cast(T, obj)
|
return cast(T, obj)
|
||||||
|
|
||||||
|
elif isinstance(obj, FieldInfo):
|
||||||
|
from langchain_core.pydantic_v1 import Field
|
||||||
|
|
||||||
|
wrapped = None
|
||||||
|
if not _obj_type:
|
||||||
|
_obj_type = "attribute"
|
||||||
|
if not _name:
|
||||||
|
raise ValueError()
|
||||||
|
old_doc = obj.description
|
||||||
|
|
||||||
|
def finalize(wrapper: Callable[..., Any], new_doc: str) -> T:
|
||||||
|
return Field(
|
||||||
|
default=obj.default,
|
||||||
|
default_factory=obj.default_factory,
|
||||||
|
description=new_doc,
|
||||||
|
alias=obj.alias,
|
||||||
|
exclude=obj.exclude,
|
||||||
|
)
|
||||||
|
|
||||||
elif isinstance(obj, property):
|
elif isinstance(obj, property):
|
||||||
if not _obj_type:
|
if not _obj_type:
|
||||||
_obj_type = "attribute"
|
_obj_type = "attribute"
|
||||||
|
@ -208,11 +208,18 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC):
|
|||||||
|
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
|
|
||||||
callback_manager: Optional[BaseCallbackManager] = Field(default=None, exclude=True)
|
callback_manager: Optional[BaseCallbackManager] = deprecated(
|
||||||
"""[DEPRECATED] Callback manager to add to the run trace."""
|
name="callback_manager", since="0.1.7", removal="0.3.0", alternative="callbacks"
|
||||||
|
)(
|
||||||
|
Field(
|
||||||
|
default=None,
|
||||||
|
exclude=True,
|
||||||
|
description="Callback manager to add to the run trace.",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
rate_limiter: Optional[BaseRateLimiter] = Field(default=None, exclude=True)
|
rate_limiter: Optional[BaseRateLimiter] = Field(default=None, exclude=True)
|
||||||
"""An optional rate limiter to use for limiting the number of requests."""
|
"An optional rate limiter to use for limiting the number of requests."
|
||||||
|
|
||||||
disable_streaming: Union[bool, Literal["tool_calling"]] = False
|
disable_streaming: Union[bool, Literal["tool_calling"]] = False
|
||||||
"""Whether to disable streaming for this model.
|
"""Whether to disable streaming for this model.
|
||||||
|
@ -330,8 +330,16 @@ class ChildTool(BaseTool):
|
|||||||
|
|
||||||
callbacks: Callbacks = Field(default=None, exclude=True)
|
callbacks: Callbacks = Field(default=None, exclude=True)
|
||||||
"""Callbacks to be called during tool execution."""
|
"""Callbacks to be called during tool execution."""
|
||||||
callback_manager: Optional[BaseCallbackManager] = Field(default=None, exclude=True)
|
|
||||||
"""Deprecated. Please use callbacks instead."""
|
callback_manager: Optional[BaseCallbackManager] = deprecated(
|
||||||
|
name="callback_manager", since="0.1.7", removal="0.3.0", alternative="callbacks"
|
||||||
|
)(
|
||||||
|
Field(
|
||||||
|
default=None,
|
||||||
|
exclude=True,
|
||||||
|
description="Callback manager to add to the run trace.",
|
||||||
|
)
|
||||||
|
)
|
||||||
tags: Optional[List[str]] = None
|
tags: Optional[List[str]] = None
|
||||||
"""Optional list of tags associated with the tool. Defaults to None.
|
"""Optional list of tags associated with the tool. Defaults to None.
|
||||||
These tags will be associated with each call to this tool,
|
These tags will be associated with each call to this tool,
|
||||||
|
Loading…
Reference in New Issue
Block a user