Skip to content

Commit eb8f2f0

Browse files
authored
Merge branch 'master' into ruff-core-preview-2
2 parents 468d3c3 + f4e83e0 commit eb8f2f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1278
-398
lines changed

libs/core/langchain_core/_api/beta_decorator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def beta(
6363
addendum : str, optional
6464
Additional text appended directly to the final message.
6565
66+
Returns:
67+
A decorator which can be used to mark functions or classes as beta.
68+
6669
Examples:
6770
6871
.. code-block:: python

libs/core/langchain_core/_api/deprecation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def deprecated(
129129
package: str, optional
130130
The package of the deprecated object.
131131
132+
Returns:
133+
A decorator to mark a function or class as deprecated.
134+
132135
Examples:
133136
134137
.. code-block:: python
@@ -545,6 +548,15 @@ def rename_parameter(
545548
is passed to *func*, a DeprecationWarning is emitted, and its value is
546549
used, even if *new* is also passed by keyword.
547550
551+
Args:
552+
since: The version in which the parameter was renamed.
553+
removal: The version in which the old parameter will be removed.
554+
old: The old parameter name.
555+
new: The new parameter name.
556+
557+
Returns:
558+
A decorator indicating that a parameter was renamed.
559+
548560
Example:
549561
550562
.. code-block:: python

libs/core/langchain_core/_api/path.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
def get_relative_path(
1313
file: Union[Path, str], *, relative_to: Path = PACKAGE_DIR
1414
) -> str:
15-
"""Get the path of the file as a relative path to the package directory."""
15+
"""Get the path of the file as a relative path to the package directory.
16+
17+
Args:
18+
file: The file path to convert.
19+
relative_to: The base path to make the file path relative to.
20+
21+
Returns:
22+
The relative path as a string.
23+
"""
1624
if isinstance(file, str):
1725
file = Path(file)
1826
return str(file.relative_to(relative_to))
@@ -24,7 +32,16 @@ def as_import_path(
2432
suffix: Optional[str] = None,
2533
relative_to: Path = PACKAGE_DIR,
2634
) -> str:
27-
"""Path of the file as a LangChain import exclude langchain top namespace."""
35+
"""Path of the file as a LangChain import exclude langchain top namespace.
36+
37+
Args:
38+
file: The file path to convert.
39+
suffix: An optional suffix to append to the import path.
40+
relative_to: The base path to make the file path relative to.
41+
42+
Returns:
43+
The import path as a string.
44+
"""
2845
if isinstance(file, str):
2946
file = Path(file)
3047
path = get_relative_path(file, relative_to=relative_to)

libs/core/langchain_core/_import_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def import_attr(
1717
module_name: The name of the module to import from. If None, the attribute
1818
is imported from the package itself.
1919
package: The name of the package where the module is located.
20+
21+
Raises:
22+
ImportError: If the module cannot be found.
23+
AttributeError: If the attribute does not exist in the module or package.
24+
25+
Returns:
26+
The imported attribute.
2027
"""
2128
if module_name == "__module__" or module_name is None:
2229
try:

libs/core/langchain_core/agents.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ def is_lc_serializable(cls) -> bool:
8686
def get_lc_namespace(cls) -> list[str]:
8787
"""Get the namespace of the langchain object.
8888
89-
Default is ["langchain", "schema", "agent"].
89+
Returns:
90+
``["langchain", "schema", "agent"]``
9091
"""
9192
return ["langchain", "schema", "agent"]
9293

@@ -155,14 +156,15 @@ def __init__(self, return_values: dict, log: str, **kwargs: Any):
155156

156157
@classmethod
157158
def is_lc_serializable(cls) -> bool:
158-
"""Return whether or not the class is serializable."""
159+
"""Return True as this class is serializable."""
159160
return True
160161

161162
@classmethod
162163
def get_lc_namespace(cls) -> list[str]:
163164
"""Get the namespace of the langchain object.
164165
165-
Default namespace is ["langchain", "schema", "agent"].
166+
Returns:
167+
``["langchain", "schema", "agent"]``
166168
"""
167169
return ["langchain", "schema", "agent"]
168170

libs/core/langchain_core/callbacks/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ def __init__(
922922
self.inheritable_metadata = inheritable_metadata or {}
923923

924924
def copy(self) -> Self:
925-
"""Copy the callback manager."""
925+
"""Return a copy of the callback manager."""
926926
return self.__class__(
927927
handlers=self.handlers.copy(),
928928
inheritable_handlers=self.inheritable_handlers.copy(),

libs/core/langchain_core/callbacks/manager.py

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def trace_as_chain_group(
8888
Must have ``LANGCHAIN_TRACING_V2`` env var set to true to see the trace in
8989
LangSmith.
9090
91-
Returns:
92-
CallbackManagerForChainGroup: The callback manager for the chain group.
91+
Yields:
92+
The callback manager for the chain group.
9393
9494
Example:
9595
.. code-block:: python
@@ -170,8 +170,8 @@ async def atrace_as_chain_group(
170170
metadata (dict[str, Any], optional): The metadata to apply to all runs.
171171
Defaults to None.
172172
173-
Returns:
174-
AsyncCallbackManager: The async callback manager for the chain group.
173+
Yields:
174+
The async callback manager for the chain group.
175175
176176
.. note:
177177
Must have ``LANGCHAIN_TRACING_V2`` env var set to true to see the trace in
@@ -519,15 +519,12 @@ def on_text(
519519
self,
520520
text: str,
521521
**kwargs: Any,
522-
) -> Any:
522+
) -> None:
523523
"""Run when a text is received.
524524
525525
Args:
526526
text (str): The received text.
527527
**kwargs (Any): Additional keyword arguments.
528-
529-
Returns:
530-
Any: The result of the callback.
531528
"""
532529
if not self.handlers:
533530
return
@@ -607,16 +604,12 @@ async def on_text(
607604
self,
608605
text: str,
609606
**kwargs: Any,
610-
) -> Any:
607+
) -> None:
611608
"""Run when a text is received.
612609
613610
Args:
614611
text (str): The received text.
615612
**kwargs (Any): Additional keyword arguments.
616-
617-
Returns:
618-
Any: The result of the callback.
619-
620613
"""
621614
if not self.handlers:
622615
return
@@ -914,16 +907,12 @@ def on_chain_error(
914907
**kwargs,
915908
)
916909

917-
def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
910+
def on_agent_action(self, action: AgentAction, **kwargs: Any) -> None:
918911
"""Run when agent action is received.
919912
920913
Args:
921914
action (AgentAction): The agent action.
922915
**kwargs (Any): Additional keyword arguments.
923-
924-
Returns:
925-
Any: The result of the callback.
926-
927916
"""
928917
if not self.handlers:
929918
return
@@ -938,16 +927,12 @@ def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
938927
**kwargs,
939928
)
940929

941-
def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> Any:
930+
def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None:
942931
"""Run when agent finish is received.
943932
944933
Args:
945934
finish (AgentFinish): The agent finish.
946935
**kwargs (Any): Additional keyword arguments.
947-
948-
Returns:
949-
Any: The result of the callback.
950-
951936
"""
952937
if not self.handlers:
953938
return
@@ -1033,16 +1018,12 @@ async def on_chain_error(
10331018
**kwargs,
10341019
)
10351020

1036-
async def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
1021+
async def on_agent_action(self, action: AgentAction, **kwargs: Any) -> None:
10371022
"""Run when agent action is received.
10381023
10391024
Args:
10401025
action (AgentAction): The agent action.
10411026
**kwargs (Any): Additional keyword arguments.
1042-
1043-
Returns:
1044-
Any: The result of the callback.
1045-
10461027
"""
10471028
if not self.handlers:
10481029
return
@@ -1057,16 +1038,12 @@ async def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
10571038
**kwargs,
10581039
)
10591040

1060-
async def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> Any:
1041+
async def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> None:
10611042
"""Run when agent finish is received.
10621043
10631044
Args:
10641045
finish (AgentFinish): The agent finish.
10651046
**kwargs (Any): Additional keyword arguments.
1066-
1067-
Returns:
1068-
Any: The result of the callback.
1069-
10701047
"""
10711048
if not self.handlers:
10721049
return
@@ -1562,6 +1539,8 @@ def on_retriever_start(
15621539
parent_run_id (UUID, optional): The ID of the parent run. Defaults to None.
15631540
**kwargs (Any): Additional keyword arguments.
15641541
1542+
Returns:
1543+
The callback manager for the retriever run.
15651544
"""
15661545
if run_id is None:
15671546
run_id = uuid.uuid4()
@@ -1608,6 +1587,9 @@ def on_custom_event(
16081587
data: The data for the adhoc event.
16091588
run_id: The ID of the run. Defaults to None.
16101589
1590+
Raises:
1591+
ValueError: If additional keyword arguments are passed.
1592+
16111593
.. versionadded:: 0.2.14
16121594
16131595
"""
@@ -1710,8 +1692,8 @@ def __init__(
17101692
self.parent_run_manager = parent_run_manager
17111693
self.ended = False
17121694

1695+
@override
17131696
def copy(self) -> CallbackManagerForChainGroup:
1714-
"""Copy the callback manager."""
17151697
return self.__class__(
17161698
handlers=self.handlers.copy(),
17171699
inheritable_handlers=self.inheritable_handlers.copy(),
@@ -2099,6 +2081,9 @@ async def on_custom_event(
20992081
data: The data for the adhoc event.
21002082
run_id: The ID of the run. Defaults to None.
21012083
2084+
Raises:
2085+
ValueError: If additional keyword arguments are passed.
2086+
21022087
.. versionadded:: 0.2.14
21032088
"""
21042089
if not self.handlers:
@@ -2249,7 +2234,7 @@ def __init__(
22492234
self.ended = False
22502235

22512236
def copy(self) -> AsyncCallbackManagerForChainGroup:
2252-
"""Copy the async callback manager."""
2237+
"""Return a copy the async callback manager."""
22532238
return self.__class__(
22542239
handlers=self.handlers.copy(),
22552240
inheritable_handlers=self.inheritable_handlers.copy(),
@@ -2385,6 +2370,9 @@ def _configure(
23852370
local_metadata (Optional[dict[str, Any]], optional): The local metadata.
23862371
Defaults to None.
23872372
2373+
Raises:
2374+
RuntimeError: If `LANGCHAIN_TRACING` is set but `LANGCHAIN_TRACING_V2` is not.
2375+
23882376
Returns:
23892377
T: The configured callback manager.
23902378
"""
@@ -2557,6 +2545,10 @@ async def adispatch_custom_event(
25572545
this is not enforced.
25582546
config: Optional config object. Mirrors the async API but not strictly needed.
25592547
2548+
Raises:
2549+
RuntimeError: If there is no parent run ID available to associate
2550+
the event with.
2551+
25602552
Example:
25612553
25622554
.. code-block:: python
@@ -2678,6 +2670,10 @@ def dispatch_custom_event(
26782670
this is not enforced.
26792671
config: Optional config object. Mirrors the async API but not strictly needed.
26802672
2673+
Raises:
2674+
RuntimeError: If there is no parent run ID available to associate
2675+
the event with.
2676+
26812677
Example:
26822678
26832679
.. code-block:: python

libs/core/langchain_core/callbacks/usage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def get_usage_metadata_callback(
101101
name (str): The name of the context variable. Defaults to
102102
``'usage_metadata_callback'``.
103103
104+
Yields:
105+
The usage metadata callback.
106+
104107
Example:
105108
.. code-block:: python
106109

libs/core/langchain_core/chat_history.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ async def aget_messages(self) -> list[BaseMessage]:
109109
110110
In general, fetching messages may involve IO to the underlying
111111
persistence layer.
112+
113+
Returns:
114+
The messages.
112115
"""
113116
from langchain_core.runnables.config import run_in_executor
114117

0 commit comments

Comments
 (0)