langchain-core 0.4.0.dev0__py3-none-any.whl → 1.0.0a2__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.
Files changed (74) 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/base.py +14 -23
  5. langchain_core/callbacks/file.py +13 -2
  6. langchain_core/callbacks/manager.py +74 -157
  7. langchain_core/callbacks/streaming_stdout.py +3 -4
  8. langchain_core/callbacks/usage.py +2 -12
  9. langchain_core/chat_history.py +6 -6
  10. langchain_core/documents/base.py +1 -1
  11. langchain_core/documents/compressor.py +9 -6
  12. langchain_core/indexing/base.py +2 -2
  13. langchain_core/language_models/_utils.py +232 -101
  14. langchain_core/language_models/base.py +35 -23
  15. langchain_core/language_models/chat_models.py +248 -54
  16. langchain_core/language_models/fake_chat_models.py +28 -81
  17. langchain_core/load/dump.py +3 -4
  18. langchain_core/messages/__init__.py +30 -24
  19. langchain_core/messages/ai.py +188 -30
  20. langchain_core/messages/base.py +164 -25
  21. langchain_core/messages/block_translators/__init__.py +89 -0
  22. langchain_core/messages/block_translators/anthropic.py +451 -0
  23. langchain_core/messages/block_translators/bedrock.py +45 -0
  24. langchain_core/messages/block_translators/bedrock_converse.py +47 -0
  25. langchain_core/messages/block_translators/google_genai.py +45 -0
  26. langchain_core/messages/block_translators/google_vertexai.py +47 -0
  27. langchain_core/messages/block_translators/groq.py +45 -0
  28. langchain_core/messages/block_translators/langchain_v0.py +164 -0
  29. langchain_core/messages/block_translators/ollama.py +45 -0
  30. langchain_core/messages/block_translators/openai.py +798 -0
  31. langchain_core/messages/{content_blocks.py → content.py} +303 -278
  32. langchain_core/messages/human.py +29 -9
  33. langchain_core/messages/system.py +29 -9
  34. langchain_core/messages/tool.py +94 -13
  35. langchain_core/messages/utils.py +34 -234
  36. langchain_core/output_parsers/base.py +14 -50
  37. langchain_core/output_parsers/json.py +2 -5
  38. langchain_core/output_parsers/list.py +2 -7
  39. langchain_core/output_parsers/openai_functions.py +5 -28
  40. langchain_core/output_parsers/openai_tools.py +49 -90
  41. langchain_core/output_parsers/pydantic.py +2 -3
  42. langchain_core/output_parsers/transform.py +12 -53
  43. langchain_core/output_parsers/xml.py +9 -17
  44. langchain_core/prompt_values.py +8 -112
  45. langchain_core/prompts/chat.py +1 -3
  46. langchain_core/runnables/base.py +500 -451
  47. langchain_core/runnables/branch.py +1 -1
  48. langchain_core/runnables/fallbacks.py +4 -4
  49. langchain_core/runnables/history.py +1 -1
  50. langchain_core/runnables/passthrough.py +3 -3
  51. langchain_core/runnables/retry.py +1 -1
  52. langchain_core/runnables/router.py +1 -1
  53. langchain_core/structured_query.py +3 -7
  54. langchain_core/tools/base.py +14 -41
  55. langchain_core/tools/convert.py +2 -22
  56. langchain_core/tools/retriever.py +1 -8
  57. langchain_core/tools/structured.py +2 -10
  58. langchain_core/tracers/_streaming.py +6 -7
  59. langchain_core/tracers/base.py +7 -14
  60. langchain_core/tracers/core.py +4 -27
  61. langchain_core/tracers/event_stream.py +4 -15
  62. langchain_core/tracers/langchain.py +3 -14
  63. langchain_core/tracers/log_stream.py +2 -3
  64. langchain_core/utils/_merge.py +45 -7
  65. langchain_core/utils/function_calling.py +22 -9
  66. langchain_core/utils/utils.py +29 -0
  67. langchain_core/version.py +1 -1
  68. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0a2.dist-info}/METADATA +7 -9
  69. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0a2.dist-info}/RECORD +71 -64
  70. langchain_core/v1/__init__.py +0 -1
  71. langchain_core/v1/chat_models.py +0 -1047
  72. langchain_core/v1/messages.py +0 -755
  73. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0a2.dist-info}/WHEEL +0 -0
  74. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0a2.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()
@@ -7,8 +7,6 @@ from typing import TYPE_CHECKING, Any, Optional, Union
7
7
 
8
8
  from typing_extensions import Self
9
9
 
10
- from langchain_core.v1.messages import AIMessage, AIMessageChunk, MessageV1
11
-
12
10
  if TYPE_CHECKING:
13
11
  from collections.abc import Sequence
14
12
  from uuid import UUID
@@ -68,9 +66,7 @@ class LLMManagerMixin:
68
66
  self,
69
67
  token: str,
70
68
  *,
71
- chunk: Optional[
72
- Union[GenerationChunk, ChatGenerationChunk, AIMessageChunk]
73
- ] = None,
69
+ chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None,
74
70
  run_id: UUID,
75
71
  parent_run_id: Optional[UUID] = None,
76
72
  **kwargs: Any,
@@ -79,8 +75,8 @@ class LLMManagerMixin:
79
75
 
80
76
  Args:
81
77
  token (str): The new token.
82
- chunk (GenerationChunk | ChatGenerationChunk | AIMessageChunk): The new
83
- generated chunk, containing content and other information.
78
+ chunk (GenerationChunk | ChatGenerationChunk): The new generated chunk,
79
+ containing content and other information.
84
80
  run_id (UUID): The run ID. This is the ID of the current run.
85
81
  parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
86
82
  kwargs (Any): Additional keyword arguments.
@@ -88,7 +84,7 @@ class LLMManagerMixin:
88
84
 
89
85
  def on_llm_end(
90
86
  self,
91
- response: Union[LLMResult, AIMessage],
87
+ response: LLMResult,
92
88
  *,
93
89
  run_id: UUID,
94
90
  parent_run_id: Optional[UUID] = None,
@@ -97,7 +93,7 @@ class LLMManagerMixin:
97
93
  """Run when LLM ends running.
98
94
 
99
95
  Args:
100
- response (LLMResult | AIMessage): The response which was generated.
96
+ response (LLMResult): The response which was generated.
101
97
  run_id (UUID): The run ID. This is the ID of the current run.
102
98
  parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
103
99
  kwargs (Any): Additional keyword arguments.
@@ -265,7 +261,7 @@ class CallbackManagerMixin:
265
261
  def on_chat_model_start(
266
262
  self,
267
263
  serialized: dict[str, Any],
268
- messages: Union[list[list[BaseMessage]], list[MessageV1]],
264
+ messages: list[list[BaseMessage]],
269
265
  *,
270
266
  run_id: UUID,
271
267
  parent_run_id: Optional[UUID] = None,
@@ -443,9 +439,6 @@ class BaseCallbackHandler(
443
439
  run_inline: bool = False
444
440
  """Whether to run the callback inline."""
445
441
 
446
- accepts_new_messages: bool = False
447
- """Whether the callback accepts new message format."""
448
-
449
442
  @property
450
443
  def ignore_llm(self) -> bool:
451
444
  """Whether to ignore LLM callbacks."""
@@ -516,7 +509,7 @@ class AsyncCallbackHandler(BaseCallbackHandler):
516
509
  async def on_chat_model_start(
517
510
  self,
518
511
  serialized: dict[str, Any],
519
- messages: Union[list[list[BaseMessage]], list[MessageV1]],
512
+ messages: list[list[BaseMessage]],
520
513
  *,
521
514
  run_id: UUID,
522
515
  parent_run_id: Optional[UUID] = None,
@@ -547,9 +540,7 @@ class AsyncCallbackHandler(BaseCallbackHandler):
547
540
  self,
548
541
  token: str,
549
542
  *,
550
- chunk: Optional[
551
- Union[GenerationChunk, ChatGenerationChunk, AIMessageChunk]
552
- ] = None,
543
+ chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None,
553
544
  run_id: UUID,
554
545
  parent_run_id: Optional[UUID] = None,
555
546
  tags: Optional[list[str]] = None,
@@ -559,8 +550,8 @@ class AsyncCallbackHandler(BaseCallbackHandler):
559
550
 
560
551
  Args:
561
552
  token (str): The new token.
562
- chunk (GenerationChunk | ChatGenerationChunk | AIMessageChunk): The new
563
- generated chunk, containing content and other information.
553
+ chunk (GenerationChunk | ChatGenerationChunk): The new generated chunk,
554
+ containing content and other information.
564
555
  run_id (UUID): The run ID. This is the ID of the current run.
565
556
  parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
566
557
  tags (Optional[list[str]]): The tags.
@@ -569,7 +560,7 @@ class AsyncCallbackHandler(BaseCallbackHandler):
569
560
 
570
561
  async def on_llm_end(
571
562
  self,
572
- response: Union[LLMResult, AIMessage],
563
+ response: LLMResult,
573
564
  *,
574
565
  run_id: UUID,
575
566
  parent_run_id: Optional[UUID] = None,
@@ -579,7 +570,7 @@ class AsyncCallbackHandler(BaseCallbackHandler):
579
570
  """Run when LLM ends running.
580
571
 
581
572
  Args:
582
- response (LLMResult | AIMessage): The response which was generated.
573
+ response (LLMResult): The response which was generated.
583
574
  run_id (UUID): The run ID. This is the ID of the current run.
584
575
  parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
585
576
  tags (Optional[list[str]]): The tags.
@@ -603,8 +594,8 @@ class AsyncCallbackHandler(BaseCallbackHandler):
603
594
  parent_run_id: The parent run ID. This is the ID of the parent run.
604
595
  tags: The tags.
605
596
  kwargs (Any): Additional keyword arguments.
606
- - response (LLMResult | AIMessage): The response which was generated
607
- before the error occurred.
597
+ - response (LLMResult): The response which was generated before
598
+ the error occurred.
608
599
  """
609
600
 
610
601
  async def on_chain_start(
@@ -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")