langchain-core 0.3.74__py3-none-any.whl → 0.3.75__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of langchain-core might be problematic. Click here for more details.

Files changed (41) hide show
  1. langchain_core/_api/beta_decorator.py +2 -2
  2. langchain_core/_api/deprecation.py +1 -1
  3. langchain_core/beta/runnables/context.py +1 -1
  4. langchain_core/callbacks/file.py +13 -2
  5. langchain_core/callbacks/manager.py +55 -16
  6. langchain_core/chat_history.py +6 -6
  7. langchain_core/documents/base.py +1 -1
  8. langchain_core/documents/compressor.py +9 -6
  9. langchain_core/indexing/base.py +2 -2
  10. langchain_core/language_models/base.py +33 -19
  11. langchain_core/language_models/chat_models.py +39 -20
  12. langchain_core/language_models/fake_chat_models.py +5 -4
  13. langchain_core/load/dump.py +3 -4
  14. langchain_core/messages/ai.py +4 -1
  15. langchain_core/messages/modifier.py +1 -1
  16. langchain_core/messages/tool.py +3 -3
  17. langchain_core/messages/utils.py +18 -17
  18. langchain_core/output_parsers/openai_tools.py +2 -0
  19. langchain_core/output_parsers/transform.py +2 -2
  20. langchain_core/output_parsers/xml.py +4 -3
  21. langchain_core/prompts/chat.py +1 -3
  22. langchain_core/runnables/base.py +507 -451
  23. langchain_core/runnables/branch.py +1 -1
  24. langchain_core/runnables/config.py +2 -2
  25. langchain_core/runnables/fallbacks.py +4 -4
  26. langchain_core/runnables/graph.py +3 -3
  27. langchain_core/runnables/history.py +1 -1
  28. langchain_core/runnables/passthrough.py +3 -3
  29. langchain_core/runnables/retry.py +1 -1
  30. langchain_core/runnables/router.py +1 -1
  31. langchain_core/structured_query.py +3 -7
  32. langchain_core/tools/structured.py +1 -1
  33. langchain_core/tracers/_streaming.py +6 -7
  34. langchain_core/tracers/event_stream.py +1 -1
  35. langchain_core/tracers/log_stream.py +1 -1
  36. langchain_core/utils/function_calling.py +12 -10
  37. langchain_core/version.py +1 -1
  38. {langchain_core-0.3.74.dist-info → langchain_core-0.3.75.dist-info}/METADATA +6 -8
  39. {langchain_core-0.3.74.dist-info → langchain_core-0.3.75.dist-info}/RECORD +41 -41
  40. {langchain_core-0.3.74.dist-info → langchain_core-0.3.75.dist-info}/WHEEL +0 -0
  41. {langchain_core-0.3.74.dist-info → langchain_core-0.3.75.dist-info}/entry_points.txt +0 -0
@@ -144,10 +144,9 @@ def beta(
144
144
  obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
145
145
  warn_if_direct_instance
146
146
  )
147
- return cast("T", obj)
147
+ return obj
148
148
 
149
149
  elif isinstance(obj, property):
150
- # note(erick): this block doesn't seem to be used?
151
150
  if not _obj_type:
152
151
  _obj_type = "attribute"
153
152
  wrapped = None
@@ -168,6 +167,7 @@ def beta(
168
167
  self.__orig_fget = fget
169
168
  self.__orig_fset = fset
170
169
  self.__orig_fdel = fdel
170
+ self.__doc__ = doc
171
171
 
172
172
  def __get__(
173
173
  self, instance: Any, owner: Union[type, None] = None
@@ -225,7 +225,7 @@ def deprecated(
225
225
  obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
226
226
  warn_if_direct_instance
227
227
  )
228
- return cast("T", obj)
228
+ return obj
229
229
 
230
230
  elif isinstance(obj, FieldInfoV1):
231
231
  wrapped = None
@@ -253,7 +253,7 @@ class ContextSet(RunnableSerializable):
253
253
  """
254
254
  if key is not None:
255
255
  kwargs[key] = value
256
- super().__init__( # type: ignore[call-arg]
256
+ super().__init__(
257
257
  keys={
258
258
  k: _coerce_set_value(v) if v is not None else None
259
259
  for k, v in kwargs.items()
@@ -49,7 +49,7 @@ class FileCallbackHandler(BaseCallbackHandler):
49
49
  mode: The file open mode. Defaults to ``'a'`` (append).
50
50
  color: Default color for text output. Defaults to ``None``.
51
51
 
52
- Note:
52
+ .. note::
53
53
  When not used as a context manager, a deprecation warning will be issued
54
54
  on first use. The file will be opened immediately in ``__init__`` and closed
55
55
  in ``__del__`` or when ``close()`` is called explicitly.
@@ -65,6 +65,7 @@ class FileCallbackHandler(BaseCallbackHandler):
65
65
  filename: Path to the output file.
66
66
  mode: File open mode (e.g., ``'w'``, ``'a'``, ``'x'``). Defaults to ``'a'``.
67
67
  color: Default text color for output. Defaults to ``None``.
68
+
68
69
  """
69
70
  self.filename = filename
70
71
  self.mode = mode
@@ -82,9 +83,10 @@ class FileCallbackHandler(BaseCallbackHandler):
82
83
  Returns:
83
84
  The FileCallbackHandler instance.
84
85
 
85
- Note:
86
+ .. note::
86
87
  The file is already opened in ``__init__``, so this just marks that
87
88
  the handler is being used as a context manager.
89
+
88
90
  """
89
91
  self._file_opened_in_context = True
90
92
  return self
@@ -101,6 +103,7 @@ class FileCallbackHandler(BaseCallbackHandler):
101
103
  exc_type: Exception type if an exception occurred.
102
104
  exc_val: Exception value if an exception occurred.
103
105
  exc_tb: Exception traceback if an exception occurred.
106
+
104
107
  """
105
108
  self.close()
106
109
 
@@ -113,6 +116,7 @@ class FileCallbackHandler(BaseCallbackHandler):
113
116
 
114
117
  This method is safe to call multiple times and will only close
115
118
  the file if it's currently open.
119
+
116
120
  """
117
121
  if hasattr(self, "file") and self.file and not self.file.closed:
118
122
  self.file.close()
@@ -133,6 +137,7 @@ class FileCallbackHandler(BaseCallbackHandler):
133
137
 
134
138
  Raises:
135
139
  RuntimeError: If the file is closed or not available.
140
+
136
141
  """
137
142
  global _GLOBAL_DEPRECATION_WARNED # noqa: PLW0603
138
143
  if not self._file_opened_in_context and not _GLOBAL_DEPRECATION_WARNED:
@@ -163,6 +168,7 @@ class FileCallbackHandler(BaseCallbackHandler):
163
168
  serialized: The serialized chain information.
164
169
  inputs: The inputs to the chain.
165
170
  **kwargs: Additional keyword arguments that may contain ``'name'``.
171
+
166
172
  """
167
173
  name = (
168
174
  kwargs.get("name")
@@ -178,6 +184,7 @@ class FileCallbackHandler(BaseCallbackHandler):
178
184
  Args:
179
185
  outputs: The outputs of the chain.
180
186
  **kwargs: Additional keyword arguments.
187
+
181
188
  """
182
189
  self._write("\n> Finished chain.", end="\n")
183
190
 
@@ -192,6 +199,7 @@ class FileCallbackHandler(BaseCallbackHandler):
192
199
  color: Color override for this specific output. If ``None``, uses
193
200
  ``self.color``.
194
201
  **kwargs: Additional keyword arguments.
202
+
195
203
  """
196
204
  self._write(action.log, color=color or self.color)
197
205
 
@@ -213,6 +221,7 @@ class FileCallbackHandler(BaseCallbackHandler):
213
221
  observation_prefix: Optional prefix to write before the output.
214
222
  llm_prefix: Optional prefix to write after the output.
215
223
  **kwargs: Additional keyword arguments.
224
+
216
225
  """
217
226
  if observation_prefix is not None:
218
227
  self._write(f"\n{observation_prefix}")
@@ -232,6 +241,7 @@ class FileCallbackHandler(BaseCallbackHandler):
232
241
  ``self.color``.
233
242
  end: String appended after the text. Defaults to ``""``.
234
243
  **kwargs: Additional keyword arguments.
244
+
235
245
  """
236
246
  self._write(text, color=color or self.color, end=end)
237
247
 
@@ -246,5 +256,6 @@ class FileCallbackHandler(BaseCallbackHandler):
246
256
  color: Color override for this specific output. If ``None``, uses
247
257
  ``self.color``.
248
258
  **kwargs: Additional keyword arguments.
259
+
249
260
  """
250
261
  self._write(finish.log, color=color or self.color, end="\n")
@@ -11,15 +11,7 @@ from abc import ABC, abstractmethod
11
11
  from concurrent.futures import ThreadPoolExecutor
12
12
  from contextlib import asynccontextmanager, contextmanager
13
13
  from contextvars import copy_context
14
- from typing import (
15
- TYPE_CHECKING,
16
- Any,
17
- Callable,
18
- Optional,
19
- TypeVar,
20
- Union,
21
- cast,
22
- )
14
+ from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, Union, cast
23
15
  from uuid import UUID
24
16
 
25
17
  from langsmith.run_helpers import get_tracing_context
@@ -92,7 +84,8 @@ def trace_as_chain_group(
92
84
  metadata (dict[str, Any], optional): The metadata to apply to all runs.
93
85
  Defaults to None.
94
86
 
95
- Note: must have LANGCHAIN_TRACING_V2 env var set to true to see the trace in LangSmith.
87
+ .. note:
88
+ Must have ``LANGCHAIN_TRACING_V2`` env var set to true to see the trace in LangSmith.
96
89
 
97
90
  Returns:
98
91
  CallbackManagerForChainGroup: The callback manager for the chain group.
@@ -177,7 +170,8 @@ async def atrace_as_chain_group(
177
170
  Returns:
178
171
  AsyncCallbackManager: The async callback manager for the chain group.
179
172
 
180
- Note: must have LANGCHAIN_TRACING_V2 env var set to true to see the trace in LangSmith.
173
+ .. note:
174
+ Must have ``LANGCHAIN_TRACING_V2`` env var set to true to see the trace in LangSmith.
181
175
 
182
176
  Example:
183
177
  .. code-block:: python
@@ -234,6 +228,7 @@ def shielded(func: Func) -> Func:
234
228
 
235
229
  Returns:
236
230
  Callable: The shielded function
231
+
237
232
  """
238
233
 
239
234
  @functools.wraps(func)
@@ -252,15 +247,17 @@ def handle_event(
252
247
  ) -> None:
253
248
  """Generic event handler for CallbackManager.
254
249
 
255
- Note: This function is used by LangServe to handle events.
250
+ .. note::
251
+ This function is used by ``LangServe`` to handle events.
256
252
 
257
253
  Args:
258
254
  handlers: The list of handlers that will handle the event.
259
- event_name: The name of the event (e.g., "on_llm_start").
255
+ event_name: The name of the event (e.g., ``'on_llm_start'``).
260
256
  ignore_condition_name: Name of the attribute defined on handler
261
257
  that if True will cause the handler to be skipped for the given event.
262
258
  *args: The arguments to pass to the event handler.
263
259
  **kwargs: The keyword arguments to pass to the event handler
260
+
264
261
  """
265
262
  coros: list[Coroutine[Any, Any, Any]] = []
266
263
 
@@ -415,17 +412,19 @@ async def ahandle_event(
415
412
  *args: Any,
416
413
  **kwargs: Any,
417
414
  ) -> None:
418
- """Async generic event handler for AsyncCallbackManager.
415
+ """Async generic event handler for ``AsyncCallbackManager``.
419
416
 
420
- Note: This function is used by LangServe to handle events.
417
+ .. note::
418
+ This function is used by ``LangServe`` to handle events.
421
419
 
422
420
  Args:
423
421
  handlers: The list of handlers that will handle the event.
424
- event_name: The name of the event (e.g., "on_llm_start").
422
+ event_name: The name of the event (e.g., ``'on_llm_start'``).
425
423
  ignore_condition_name: Name of the attribute defined on handler
426
424
  that if True will cause the handler to be skipped for the given event.
427
425
  *args: The arguments to pass to the event handler.
428
426
  **kwargs: The keyword arguments to pass to the event handler.
427
+
429
428
  """
430
429
  for handler in [h for h in handlers if h.run_inline]:
431
430
  await _ahandle_event_for_handler(
@@ -477,6 +476,7 @@ class BaseRunManager(RunManagerMixin):
477
476
  Defaults to None.
478
477
  inheritable_metadata (Optional[dict[str, Any]]): The inheritable metadata.
479
478
  Defaults to None.
479
+
480
480
  """
481
481
  self.run_id = run_id
482
482
  self.handlers = handlers
@@ -493,6 +493,7 @@ class BaseRunManager(RunManagerMixin):
493
493
 
494
494
  Returns:
495
495
  BaseRunManager: The noop manager.
496
+
496
497
  """
497
498
  return cls(
498
499
  run_id=uuid.uuid4(),
@@ -545,6 +546,7 @@ class RunManager(BaseRunManager):
545
546
  Args:
546
547
  retry_state (RetryCallState): The retry state.
547
548
  **kwargs (Any): Additional keyword arguments.
549
+
548
550
  """
549
551
  if not self.handlers:
550
552
  return
@@ -572,6 +574,7 @@ class ParentRunManager(RunManager):
572
574
 
573
575
  Returns:
574
576
  CallbackManager: The child callback manager.
577
+
575
578
  """
576
579
  manager = CallbackManager(handlers=[], parent_run_id=self.run_id)
577
580
  manager.set_handlers(self.inheritable_handlers)
@@ -591,6 +594,7 @@ class AsyncRunManager(BaseRunManager, ABC):
591
594
 
592
595
  Returns:
593
596
  RunManager: The sync RunManager.
597
+
594
598
  """
595
599
 
596
600
  async def on_text(
@@ -606,6 +610,7 @@ class AsyncRunManager(BaseRunManager, ABC):
606
610
 
607
611
  Returns:
608
612
  Any: The result of the callback.
613
+
609
614
  """
610
615
  if not self.handlers:
611
616
  return
@@ -630,6 +635,7 @@ class AsyncRunManager(BaseRunManager, ABC):
630
635
  Args:
631
636
  retry_state (RetryCallState): The retry state.
632
637
  **kwargs (Any): Additional keyword arguments.
638
+
633
639
  """
634
640
  if not self.handlers:
635
641
  return
@@ -657,6 +663,7 @@ class AsyncParentRunManager(AsyncRunManager):
657
663
 
658
664
  Returns:
659
665
  AsyncCallbackManager: The child callback manager.
666
+
660
667
  """
661
668
  manager = AsyncCallbackManager(handlers=[], parent_run_id=self.run_id)
662
669
  manager.set_handlers(self.inheritable_handlers)
@@ -684,6 +691,7 @@ class CallbackManagerForLLMRun(RunManager, LLMManagerMixin):
684
691
  chunk (Optional[Union[GenerationChunk, ChatGenerationChunk]], optional):
685
692
  The chunk. Defaults to None.
686
693
  **kwargs (Any): Additional keyword arguments.
694
+
687
695
  """
688
696
  if not self.handlers:
689
697
  return
@@ -705,6 +713,7 @@ class CallbackManagerForLLMRun(RunManager, LLMManagerMixin):
705
713
  Args:
706
714
  response (LLMResult): The LLM result.
707
715
  **kwargs (Any): Additional keyword arguments.
716
+
708
717
  """
709
718
  if not self.handlers:
710
719
  return
@@ -754,6 +763,7 @@ class AsyncCallbackManagerForLLMRun(AsyncRunManager, LLMManagerMixin):
754
763
 
755
764
  Returns:
756
765
  CallbackManagerForLLMRun: The sync RunManager.
766
+
757
767
  """
758
768
  return CallbackManagerForLLMRun(
759
769
  run_id=self.run_id,
@@ -780,6 +790,7 @@ class AsyncCallbackManagerForLLMRun(AsyncRunManager, LLMManagerMixin):
780
790
  chunk (Optional[Union[GenerationChunk, ChatGenerationChunk]], optional):
781
791
  The chunk. Defaults to None.
782
792
  **kwargs (Any): Additional keyword arguments.
793
+
783
794
  """
784
795
  if not self.handlers:
785
796
  return
@@ -802,6 +813,7 @@ class AsyncCallbackManagerForLLMRun(AsyncRunManager, LLMManagerMixin):
802
813
  Args:
803
814
  response (LLMResult): The LLM result.
804
815
  **kwargs (Any): Additional keyword arguments.
816
+
805
817
  """
806
818
  if not self.handlers:
807
819
  return
@@ -856,6 +868,7 @@ class CallbackManagerForChainRun(ParentRunManager, ChainManagerMixin):
856
868
  Args:
857
869
  outputs (Union[dict[str, Any], Any]): The outputs of the chain.
858
870
  **kwargs (Any): Additional keyword arguments.
871
+
859
872
  """
860
873
  if not self.handlers:
861
874
  return
@@ -880,6 +893,7 @@ class CallbackManagerForChainRun(ParentRunManager, ChainManagerMixin):
880
893
  Args:
881
894
  error (Exception or KeyboardInterrupt): The error.
882
895
  **kwargs (Any): Additional keyword arguments.
896
+
883
897
  """
884
898
  if not self.handlers:
885
899
  return
@@ -903,6 +917,7 @@ class CallbackManagerForChainRun(ParentRunManager, ChainManagerMixin):
903
917
 
904
918
  Returns:
905
919
  Any: The result of the callback.
920
+
906
921
  """
907
922
  if not self.handlers:
908
923
  return
@@ -926,6 +941,7 @@ class CallbackManagerForChainRun(ParentRunManager, ChainManagerMixin):
926
941
 
927
942
  Returns:
928
943
  Any: The result of the callback.
944
+
929
945
  """
930
946
  if not self.handlers:
931
947
  return
@@ -970,6 +986,7 @@ class AsyncCallbackManagerForChainRun(AsyncParentRunManager, ChainManagerMixin):
970
986
  Args:
971
987
  outputs (Union[dict[str, Any], Any]): The outputs of the chain.
972
988
  **kwargs (Any): Additional keyword arguments.
989
+
973
990
  """
974
991
  if not self.handlers:
975
992
  return
@@ -995,6 +1012,7 @@ class AsyncCallbackManagerForChainRun(AsyncParentRunManager, ChainManagerMixin):
995
1012
  Args:
996
1013
  error (Exception or KeyboardInterrupt): The error.
997
1014
  **kwargs (Any): Additional keyword arguments.
1015
+
998
1016
  """
999
1017
  if not self.handlers:
1000
1018
  return
@@ -1018,6 +1036,7 @@ class AsyncCallbackManagerForChainRun(AsyncParentRunManager, ChainManagerMixin):
1018
1036
 
1019
1037
  Returns:
1020
1038
  Any: The result of the callback.
1039
+
1021
1040
  """
1022
1041
  if not self.handlers:
1023
1042
  return
@@ -1041,6 +1060,7 @@ class AsyncCallbackManagerForChainRun(AsyncParentRunManager, ChainManagerMixin):
1041
1060
 
1042
1061
  Returns:
1043
1062
  Any: The result of the callback.
1063
+
1044
1064
  """
1045
1065
  if not self.handlers:
1046
1066
  return
@@ -1069,6 +1089,7 @@ class CallbackManagerForToolRun(ParentRunManager, ToolManagerMixin):
1069
1089
  Args:
1070
1090
  output (Any): The output of the tool.
1071
1091
  **kwargs (Any): The keyword arguments to pass to the event handler
1092
+
1072
1093
  """
1073
1094
  if not self.handlers:
1074
1095
  return
@@ -1093,6 +1114,7 @@ class CallbackManagerForToolRun(ParentRunManager, ToolManagerMixin):
1093
1114
  Args:
1094
1115
  error (Exception or KeyboardInterrupt): The error.
1095
1116
  **kwargs (Any): Additional keyword arguments.
1117
+
1096
1118
  """
1097
1119
  if not self.handlers:
1098
1120
  return
@@ -1134,6 +1156,7 @@ class AsyncCallbackManagerForToolRun(AsyncParentRunManager, ToolManagerMixin):
1134
1156
  Args:
1135
1157
  output (Any): The output of the tool.
1136
1158
  **kwargs (Any): Additional keyword arguments.
1159
+
1137
1160
  """
1138
1161
  if not self.handlers:
1139
1162
  return
@@ -1158,6 +1181,7 @@ class AsyncCallbackManagerForToolRun(AsyncParentRunManager, ToolManagerMixin):
1158
1181
  Args:
1159
1182
  error (Exception or KeyboardInterrupt): The error.
1160
1183
  **kwargs (Any): Additional keyword arguments.
1184
+
1161
1185
  """
1162
1186
  if not self.handlers:
1163
1187
  return
@@ -1186,6 +1210,7 @@ class CallbackManagerForRetrieverRun(ParentRunManager, RetrieverManagerMixin):
1186
1210
  Args:
1187
1211
  documents (Sequence[Document]): The retrieved documents.
1188
1212
  **kwargs (Any): Additional keyword arguments.
1213
+
1189
1214
  """
1190
1215
  if not self.handlers:
1191
1216
  return
@@ -1210,6 +1235,7 @@ class CallbackManagerForRetrieverRun(ParentRunManager, RetrieverManagerMixin):
1210
1235
  Args:
1211
1236
  error (BaseException): The error.
1212
1237
  **kwargs (Any): Additional keyword arguments.
1238
+
1213
1239
  """
1214
1240
  if not self.handlers:
1215
1241
  return
@@ -1236,6 +1262,7 @@ class AsyncCallbackManagerForRetrieverRun(
1236
1262
 
1237
1263
  Returns:
1238
1264
  CallbackManagerForRetrieverRun: The sync RunManager.
1265
+
1239
1266
  """
1240
1267
  return CallbackManagerForRetrieverRun(
1241
1268
  run_id=self.run_id,
@@ -1257,6 +1284,7 @@ class AsyncCallbackManagerForRetrieverRun(
1257
1284
  Args:
1258
1285
  documents (Sequence[Document]): The retrieved documents.
1259
1286
  **kwargs (Any): Additional keyword arguments.
1287
+
1260
1288
  """
1261
1289
  if not self.handlers:
1262
1290
  return
@@ -1282,6 +1310,7 @@ class AsyncCallbackManagerForRetrieverRun(
1282
1310
  Args:
1283
1311
  error (BaseException): The error.
1284
1312
  **kwargs (Any): Additional keyword arguments.
1313
+
1285
1314
  """
1286
1315
  if not self.handlers:
1287
1316
  return
@@ -1318,6 +1347,7 @@ class CallbackManager(BaseCallbackManager):
1318
1347
  Returns:
1319
1348
  list[CallbackManagerForLLMRun]: A callback manager for each
1320
1349
  prompt as an LLM run.
1350
+
1321
1351
  """
1322
1352
  managers = []
1323
1353
  for i, prompt in enumerate(prompts):
@@ -1369,6 +1399,7 @@ class CallbackManager(BaseCallbackManager):
1369
1399
  Returns:
1370
1400
  list[CallbackManagerForLLMRun]: A callback manager for each
1371
1401
  list of messages as an LLM run.
1402
+
1372
1403
  """
1373
1404
  managers = []
1374
1405
  for message_list in messages:
@@ -1422,6 +1453,7 @@ class CallbackManager(BaseCallbackManager):
1422
1453
 
1423
1454
  Returns:
1424
1455
  CallbackManagerForChainRun: The callback manager for the chain run.
1456
+
1425
1457
  """
1426
1458
  if run_id is None:
1427
1459
  run_id = uuid.uuid4()
@@ -1476,6 +1508,7 @@ class CallbackManager(BaseCallbackManager):
1476
1508
 
1477
1509
  Returns:
1478
1510
  CallbackManagerForToolRun: The callback manager for the tool run.
1511
+
1479
1512
  """
1480
1513
  if run_id is None:
1481
1514
  run_id = uuid.uuid4()
@@ -1522,6 +1555,7 @@ class CallbackManager(BaseCallbackManager):
1522
1555
  run_id (UUID, optional): The ID of the run. Defaults to None.
1523
1556
  parent_run_id (UUID, optional): The ID of the parent run. Defaults to None.
1524
1557
  **kwargs (Any): Additional keyword arguments.
1558
+
1525
1559
  """
1526
1560
  if run_id is None:
1527
1561
  run_id = uuid.uuid4()
@@ -1569,6 +1603,7 @@ class CallbackManager(BaseCallbackManager):
1569
1603
  run_id: The ID of the run. Defaults to None.
1570
1604
 
1571
1605
  .. versionadded:: 0.2.14
1606
+
1572
1607
  """
1573
1608
  if not self.handlers:
1574
1609
  return
@@ -1623,6 +1658,7 @@ class CallbackManager(BaseCallbackManager):
1623
1658
 
1624
1659
  Returns:
1625
1660
  CallbackManager: The configured callback manager.
1661
+
1626
1662
  """
1627
1663
  return _configure(
1628
1664
  cls,
@@ -1657,6 +1693,7 @@ class CallbackManagerForChainGroup(CallbackManager):
1657
1693
  parent_run_id (Optional[UUID]): The ID of the parent run. Defaults to None.
1658
1694
  parent_run_manager (CallbackManagerForChainRun): The parent run manager.
1659
1695
  **kwargs (Any): Additional keyword arguments.
1696
+
1660
1697
  """
1661
1698
  super().__init__(
1662
1699
  handlers,
@@ -1745,6 +1782,7 @@ class CallbackManagerForChainGroup(CallbackManager):
1745
1782
  Args:
1746
1783
  outputs (Union[dict[str, Any], Any]): The outputs of the chain.
1747
1784
  **kwargs (Any): Additional keyword arguments.
1785
+
1748
1786
  """
1749
1787
  self.ended = True
1750
1788
  return self.parent_run_manager.on_chain_end(outputs, **kwargs)
@@ -1759,6 +1797,7 @@ class CallbackManagerForChainGroup(CallbackManager):
1759
1797
  Args:
1760
1798
  error (Exception or KeyboardInterrupt): The error.
1761
1799
  **kwargs (Any): Additional keyword arguments.
1800
+
1762
1801
  """
1763
1802
  self.ended = True
1764
1803
  return self.parent_run_manager.on_chain_error(error, **kwargs)
@@ -117,9 +117,9 @@ class BaseChatMessageHistory(ABC):
117
117
  def add_user_message(self, message: Union[HumanMessage, str]) -> None:
118
118
  """Convenience method for adding a human message string to the store.
119
119
 
120
- Please note that this is a convenience method. Code should favor the
121
- bulk add_messages interface instead to save on round-trips to the underlying
122
- persistence layer.
120
+ .. note::
121
+ This is a convenience method. Code should favor the bulk ``add_messages``
122
+ interface instead to save on round-trips to the persistence layer.
123
123
 
124
124
  This method may be deprecated in a future release.
125
125
 
@@ -134,9 +134,9 @@ class BaseChatMessageHistory(ABC):
134
134
  def add_ai_message(self, message: Union[AIMessage, str]) -> None:
135
135
  """Convenience method for adding an AI message string to the store.
136
136
 
137
- Please note that this is a convenience method. Code should favor the bulk
138
- add_messages interface instead to save on round-trips to the underlying
139
- persistence layer.
137
+ .. note::
138
+ This is a convenience method. Code should favor the bulk ``add_messages``
139
+ interface instead to save on round-trips to the persistence layer.
140
140
 
141
141
  This method may be deprecated in a future release.
142
142
 
@@ -277,7 +277,7 @@ class Document(BaseMedia):
277
277
  """Pass page_content in as positional or named arg."""
278
278
  # my-py is complaining that page_content is not defined on the base class.
279
279
  # Here, we're relying on pydantic base class to handle the validation.
280
- super().__init__(page_content=page_content, **kwargs) # type: ignore[call-arg]
280
+ super().__init__(page_content=page_content, **kwargs)
281
281
 
282
282
  @classmethod
283
283
  def is_lc_serializable(cls) -> bool:
@@ -19,17 +19,18 @@ if TYPE_CHECKING:
19
19
  class BaseDocumentCompressor(BaseModel, ABC):
20
20
  """Base class for document compressors.
21
21
 
22
- This abstraction is primarily used for
23
- post-processing of retrieved documents.
22
+ This abstraction is primarily used for post-processing of retrieved documents.
24
23
 
25
24
  Documents matching a given query are first retrieved.
25
+
26
26
  Then the list of documents can be further processed.
27
27
 
28
- For example, one could re-rank the retrieved documents
29
- using an LLM.
28
+ For example, one could re-rank the retrieved documents using an LLM.
29
+
30
+ .. note::
31
+ Users should favor using a RunnableLambda instead of sub-classing from this
32
+ interface.
30
33
 
31
- **Note** users should favor using a RunnableLambda
32
- instead of sub-classing from this interface.
33
34
  """
34
35
 
35
36
  @abstractmethod
@@ -48,6 +49,7 @@ class BaseDocumentCompressor(BaseModel, ABC):
48
49
 
49
50
  Returns:
50
51
  The compressed documents.
52
+
51
53
  """
52
54
 
53
55
  async def acompress_documents(
@@ -65,6 +67,7 @@ class BaseDocumentCompressor(BaseModel, ABC):
65
67
 
66
68
  Returns:
67
69
  The compressed documents.
70
+
68
71
  """
69
72
  return await run_in_executor(
70
73
  None, self.compress_documents, documents, query, callbacks
@@ -488,8 +488,8 @@ class DeleteResponse(TypedDict, total=False):
488
488
  failed: Sequence[str]
489
489
  """The IDs that failed to be deleted.
490
490
 
491
- Please note that deleting an ID that
492
- does not exist is **NOT** considered a failure.
491
+ .. warning::
492
+ Deleting an ID that does not exist is **NOT** considered a failure.
493
493
  """
494
494
 
495
495
  num_failed: int