langchain-core 0.4.0.dev0__py3-none-any.whl → 1.0.0__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 (172) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +3 -4
  3. langchain_core/_api/beta_decorator.py +45 -70
  4. langchain_core/_api/deprecation.py +80 -80
  5. langchain_core/_api/path.py +22 -8
  6. langchain_core/_import_utils.py +10 -4
  7. langchain_core/agents.py +25 -21
  8. langchain_core/caches.py +53 -63
  9. langchain_core/callbacks/__init__.py +1 -8
  10. langchain_core/callbacks/base.py +341 -348
  11. langchain_core/callbacks/file.py +55 -44
  12. langchain_core/callbacks/manager.py +546 -683
  13. langchain_core/callbacks/stdout.py +29 -30
  14. langchain_core/callbacks/streaming_stdout.py +35 -36
  15. langchain_core/callbacks/usage.py +65 -70
  16. langchain_core/chat_history.py +48 -55
  17. langchain_core/document_loaders/base.py +46 -21
  18. langchain_core/document_loaders/langsmith.py +39 -36
  19. langchain_core/documents/__init__.py +0 -1
  20. langchain_core/documents/base.py +96 -74
  21. langchain_core/documents/compressor.py +12 -9
  22. langchain_core/documents/transformers.py +29 -28
  23. langchain_core/embeddings/fake.py +56 -57
  24. langchain_core/env.py +2 -3
  25. langchain_core/example_selectors/base.py +12 -0
  26. langchain_core/example_selectors/length_based.py +1 -1
  27. langchain_core/example_selectors/semantic_similarity.py +21 -25
  28. langchain_core/exceptions.py +15 -9
  29. langchain_core/globals.py +4 -163
  30. langchain_core/indexing/api.py +132 -125
  31. langchain_core/indexing/base.py +64 -67
  32. langchain_core/indexing/in_memory.py +26 -6
  33. langchain_core/language_models/__init__.py +15 -27
  34. langchain_core/language_models/_utils.py +267 -117
  35. langchain_core/language_models/base.py +92 -177
  36. langchain_core/language_models/chat_models.py +547 -407
  37. langchain_core/language_models/fake.py +11 -11
  38. langchain_core/language_models/fake_chat_models.py +72 -118
  39. langchain_core/language_models/llms.py +168 -242
  40. langchain_core/load/dump.py +8 -11
  41. langchain_core/load/load.py +32 -28
  42. langchain_core/load/mapping.py +2 -4
  43. langchain_core/load/serializable.py +50 -56
  44. langchain_core/messages/__init__.py +36 -51
  45. langchain_core/messages/ai.py +377 -150
  46. langchain_core/messages/base.py +239 -47
  47. langchain_core/messages/block_translators/__init__.py +111 -0
  48. langchain_core/messages/block_translators/anthropic.py +470 -0
  49. langchain_core/messages/block_translators/bedrock.py +94 -0
  50. langchain_core/messages/block_translators/bedrock_converse.py +297 -0
  51. langchain_core/messages/block_translators/google_genai.py +530 -0
  52. langchain_core/messages/block_translators/google_vertexai.py +21 -0
  53. langchain_core/messages/block_translators/groq.py +143 -0
  54. langchain_core/messages/block_translators/langchain_v0.py +301 -0
  55. langchain_core/messages/block_translators/openai.py +1010 -0
  56. langchain_core/messages/chat.py +2 -3
  57. langchain_core/messages/content.py +1423 -0
  58. langchain_core/messages/function.py +7 -7
  59. langchain_core/messages/human.py +44 -38
  60. langchain_core/messages/modifier.py +3 -2
  61. langchain_core/messages/system.py +40 -27
  62. langchain_core/messages/tool.py +160 -58
  63. langchain_core/messages/utils.py +527 -638
  64. langchain_core/output_parsers/__init__.py +1 -14
  65. langchain_core/output_parsers/base.py +68 -104
  66. langchain_core/output_parsers/json.py +13 -17
  67. langchain_core/output_parsers/list.py +11 -33
  68. langchain_core/output_parsers/openai_functions.py +56 -74
  69. langchain_core/output_parsers/openai_tools.py +68 -109
  70. langchain_core/output_parsers/pydantic.py +15 -13
  71. langchain_core/output_parsers/string.py +6 -2
  72. langchain_core/output_parsers/transform.py +17 -60
  73. langchain_core/output_parsers/xml.py +34 -44
  74. langchain_core/outputs/__init__.py +1 -1
  75. langchain_core/outputs/chat_generation.py +26 -11
  76. langchain_core/outputs/chat_result.py +1 -3
  77. langchain_core/outputs/generation.py +17 -6
  78. langchain_core/outputs/llm_result.py +15 -8
  79. langchain_core/prompt_values.py +29 -123
  80. langchain_core/prompts/__init__.py +3 -27
  81. langchain_core/prompts/base.py +48 -63
  82. langchain_core/prompts/chat.py +259 -288
  83. langchain_core/prompts/dict.py +19 -11
  84. langchain_core/prompts/few_shot.py +84 -90
  85. langchain_core/prompts/few_shot_with_templates.py +14 -12
  86. langchain_core/prompts/image.py +19 -14
  87. langchain_core/prompts/loading.py +6 -8
  88. langchain_core/prompts/message.py +7 -8
  89. langchain_core/prompts/prompt.py +42 -43
  90. langchain_core/prompts/string.py +37 -16
  91. langchain_core/prompts/structured.py +43 -46
  92. langchain_core/rate_limiters.py +51 -60
  93. langchain_core/retrievers.py +52 -192
  94. langchain_core/runnables/base.py +1727 -1683
  95. langchain_core/runnables/branch.py +52 -73
  96. langchain_core/runnables/config.py +89 -103
  97. langchain_core/runnables/configurable.py +128 -130
  98. langchain_core/runnables/fallbacks.py +93 -82
  99. langchain_core/runnables/graph.py +127 -127
  100. langchain_core/runnables/graph_ascii.py +63 -41
  101. langchain_core/runnables/graph_mermaid.py +87 -70
  102. langchain_core/runnables/graph_png.py +31 -36
  103. langchain_core/runnables/history.py +145 -161
  104. langchain_core/runnables/passthrough.py +141 -144
  105. langchain_core/runnables/retry.py +84 -68
  106. langchain_core/runnables/router.py +33 -37
  107. langchain_core/runnables/schema.py +79 -72
  108. langchain_core/runnables/utils.py +95 -139
  109. langchain_core/stores.py +85 -131
  110. langchain_core/structured_query.py +11 -15
  111. langchain_core/sys_info.py +31 -32
  112. langchain_core/tools/__init__.py +1 -14
  113. langchain_core/tools/base.py +221 -247
  114. langchain_core/tools/convert.py +144 -161
  115. langchain_core/tools/render.py +10 -10
  116. langchain_core/tools/retriever.py +12 -19
  117. langchain_core/tools/simple.py +52 -29
  118. langchain_core/tools/structured.py +56 -60
  119. langchain_core/tracers/__init__.py +1 -9
  120. langchain_core/tracers/_streaming.py +6 -7
  121. langchain_core/tracers/base.py +103 -112
  122. langchain_core/tracers/context.py +29 -48
  123. langchain_core/tracers/core.py +142 -105
  124. langchain_core/tracers/evaluation.py +30 -34
  125. langchain_core/tracers/event_stream.py +162 -117
  126. langchain_core/tracers/langchain.py +34 -36
  127. langchain_core/tracers/log_stream.py +87 -49
  128. langchain_core/tracers/memory_stream.py +3 -3
  129. langchain_core/tracers/root_listeners.py +18 -34
  130. langchain_core/tracers/run_collector.py +8 -20
  131. langchain_core/tracers/schemas.py +0 -125
  132. langchain_core/tracers/stdout.py +3 -3
  133. langchain_core/utils/__init__.py +1 -4
  134. langchain_core/utils/_merge.py +47 -9
  135. langchain_core/utils/aiter.py +70 -66
  136. langchain_core/utils/env.py +12 -9
  137. langchain_core/utils/function_calling.py +139 -206
  138. langchain_core/utils/html.py +7 -8
  139. langchain_core/utils/input.py +6 -6
  140. langchain_core/utils/interactive_env.py +6 -2
  141. langchain_core/utils/iter.py +48 -45
  142. langchain_core/utils/json.py +14 -4
  143. langchain_core/utils/json_schema.py +159 -43
  144. langchain_core/utils/mustache.py +32 -25
  145. langchain_core/utils/pydantic.py +67 -40
  146. langchain_core/utils/strings.py +5 -5
  147. langchain_core/utils/usage.py +1 -1
  148. langchain_core/utils/utils.py +104 -62
  149. langchain_core/vectorstores/base.py +131 -179
  150. langchain_core/vectorstores/in_memory.py +113 -182
  151. langchain_core/vectorstores/utils.py +23 -17
  152. langchain_core/version.py +1 -1
  153. langchain_core-1.0.0.dist-info/METADATA +68 -0
  154. langchain_core-1.0.0.dist-info/RECORD +172 -0
  155. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
  156. langchain_core/beta/__init__.py +0 -1
  157. langchain_core/beta/runnables/__init__.py +0 -1
  158. langchain_core/beta/runnables/context.py +0 -448
  159. langchain_core/memory.py +0 -116
  160. langchain_core/messages/content_blocks.py +0 -1435
  161. langchain_core/prompts/pipeline.py +0 -133
  162. langchain_core/pydantic_v1/__init__.py +0 -30
  163. langchain_core/pydantic_v1/dataclasses.py +0 -23
  164. langchain_core/pydantic_v1/main.py +0 -23
  165. langchain_core/tracers/langchain_v1.py +0 -23
  166. langchain_core/utils/loading.py +0 -31
  167. langchain_core/v1/__init__.py +0 -1
  168. langchain_core/v1/chat_models.py +0 -1047
  169. langchain_core/v1/messages.py +0 -755
  170. langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
  171. langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
  172. langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
@@ -5,13 +5,10 @@ from __future__ import annotations
5
5
  import asyncio
6
6
  import inspect
7
7
  import threading
8
- from collections.abc import Awaitable
8
+ from collections.abc import Awaitable, Callable
9
9
  from typing import (
10
10
  TYPE_CHECKING,
11
11
  Any,
12
- Callable,
13
- Optional,
14
- Union,
15
12
  cast,
16
13
  )
17
14
 
@@ -54,10 +51,10 @@ def identity(x: Other) -> Other:
54
51
  """Identity function.
55
52
 
56
53
  Args:
57
- x (Other): input.
54
+ x: input.
58
55
 
59
56
  Returns:
60
- Other: output.
57
+ output.
61
58
  """
62
59
  return x
63
60
 
@@ -66,10 +63,10 @@ async def aidentity(x: Other) -> Other:
66
63
  """Async identity function.
67
64
 
68
65
  Args:
69
- x (Other): input.
66
+ x: input.
70
67
 
71
68
  Returns:
72
- Other: output.
69
+ output.
73
70
  """
74
71
  return x
75
72
 
@@ -86,67 +83,66 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
86
83
  and experiment with.
87
84
 
88
85
  Examples:
86
+ ```python
87
+ from langchain_core.runnables import (
88
+ RunnableLambda,
89
+ RunnableParallel,
90
+ RunnablePassthrough,
91
+ )
89
92
 
90
- .. code-block:: python
91
-
92
- from langchain_core.runnables import (
93
- RunnableLambda,
94
- RunnableParallel,
95
- RunnablePassthrough,
96
- )
93
+ runnable = RunnableParallel(
94
+ origin=RunnablePassthrough(), modified=lambda x: x + 1
95
+ )
97
96
 
98
- runnable = RunnableParallel(
99
- origin=RunnablePassthrough(),
100
- modified=lambda x: x+1
101
- )
97
+ runnable.invoke(1) # {'origin': 1, 'modified': 2}
102
98
 
103
- runnable.invoke(1) # {'origin': 1, 'modified': 2}
104
99
 
100
+ def fake_llm(prompt: str) -> str: # Fake LLM for the example
101
+ return "completion"
105
102
 
106
- def fake_llm(prompt: str) -> str: # Fake LLM for the example
107
- return "completion"
108
103
 
109
- chain = RunnableLambda(fake_llm) | {
110
- 'original': RunnablePassthrough(), # Original LLM output
111
- 'parsed': lambda text: text[::-1] # Parsing logic
112
- }
104
+ chain = RunnableLambda(fake_llm) | {
105
+ "original": RunnablePassthrough(), # Original LLM output
106
+ "parsed": lambda text: text[::-1], # Parsing logic
107
+ }
113
108
 
114
- chain.invoke('hello') # {'original': 'completion', 'parsed': 'noitelpmoc'}
109
+ chain.invoke("hello") # {'original': 'completion', 'parsed': 'noitelpmoc'}
110
+ ```
115
111
 
116
112
  In some cases, it may be useful to pass the input through while adding some
117
113
  keys to the output. In this case, you can use the `assign` method:
118
114
 
119
- .. code-block:: python
115
+ ```python
116
+ from langchain_core.runnables import RunnablePassthrough
120
117
 
121
- from langchain_core.runnables import RunnablePassthrough
122
118
 
123
- def fake_llm(prompt: str) -> str: # Fake LLM for the example
124
- return "completion"
119
+ def fake_llm(prompt: str) -> str: # Fake LLM for the example
120
+ return "completion"
125
121
 
126
- runnable = {
127
- 'llm1': fake_llm,
128
- 'llm2': fake_llm,
129
- } | RunnablePassthrough.assign(
130
- total_chars=lambda inputs: len(inputs['llm1'] + inputs['llm2'])
131
- )
132
122
 
133
- runnable.invoke('hello')
134
- # {'llm1': 'completion', 'llm2': 'completion', 'total_chars': 20}
123
+ runnable = {
124
+ "llm1": fake_llm,
125
+ "llm2": fake_llm,
126
+ } | RunnablePassthrough.assign(
127
+ total_chars=lambda inputs: len(inputs["llm1"] + inputs["llm2"])
128
+ )
135
129
 
130
+ runnable.invoke("hello")
131
+ # {'llm1': 'completion', 'llm2': 'completion', 'total_chars': 20}
132
+ ```
136
133
  """
137
134
 
138
- input_type: Optional[type[Other]] = None
135
+ input_type: type[Other] | None = None
139
136
 
140
- func: Optional[
141
- Union[Callable[[Other], None], Callable[[Other, RunnableConfig], None]]
142
- ] = None
137
+ func: Callable[[Other], None] | Callable[[Other, RunnableConfig], None] | None = (
138
+ None
139
+ )
143
140
 
144
- afunc: Optional[
145
- Union[
146
- Callable[[Other], Awaitable[None]],
147
- Callable[[Other, RunnableConfig], Awaitable[None]],
148
- ]
149
- ] = None
141
+ afunc: (
142
+ Callable[[Other], Awaitable[None]]
143
+ | Callable[[Other, RunnableConfig], Awaitable[None]]
144
+ | None
145
+ ) = None
150
146
 
151
147
  @override
152
148
  def __repr_args__(self) -> Any:
@@ -156,23 +152,16 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
156
152
 
157
153
  def __init__(
158
154
  self,
159
- func: Optional[
160
- Union[
161
- Union[Callable[[Other], None], Callable[[Other, RunnableConfig], None]],
162
- Union[
163
- Callable[[Other], Awaitable[None]],
164
- Callable[[Other, RunnableConfig], Awaitable[None]],
165
- ],
166
- ]
167
- ] = None,
168
- afunc: Optional[
169
- Union[
170
- Callable[[Other], Awaitable[None]],
171
- Callable[[Other, RunnableConfig], Awaitable[None]],
172
- ]
173
- ] = None,
155
+ func: Callable[[Other], None]
156
+ | Callable[[Other, RunnableConfig], None]
157
+ | Callable[[Other], Awaitable[None]]
158
+ | Callable[[Other, RunnableConfig], Awaitable[None]]
159
+ | None = None,
160
+ afunc: Callable[[Other], Awaitable[None]]
161
+ | Callable[[Other, RunnableConfig], Awaitable[None]]
162
+ | None = None,
174
163
  *,
175
- input_type: Optional[type[Other]] = None,
164
+ input_type: type[Other] | None = None,
176
165
  **kwargs: Any,
177
166
  ) -> None:
178
167
  """Create e RunnablePassthrough.
@@ -186,16 +175,21 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
186
175
  afunc = func
187
176
  func = None
188
177
 
189
- super().__init__(func=func, afunc=afunc, input_type=input_type, **kwargs) # type: ignore[call-arg]
178
+ super().__init__(func=func, afunc=afunc, input_type=input_type, **kwargs)
190
179
 
191
180
  @classmethod
192
181
  @override
193
182
  def is_lc_serializable(cls) -> bool:
183
+ """Return True as this class is serializable."""
194
184
  return True
195
185
 
196
186
  @classmethod
197
- @override
198
187
  def get_lc_namespace(cls) -> list[str]:
188
+ """Get the namespace of the LangChain object.
189
+
190
+ Returns:
191
+ `["langchain", "schema", "runnable"]`
192
+ """
199
193
  return ["langchain", "schema", "runnable"]
200
194
 
201
195
  @property
@@ -212,14 +206,9 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
212
206
  @override
213
207
  def assign(
214
208
  cls,
215
- **kwargs: Union[
216
- Runnable[dict[str, Any], Any],
217
- Callable[[dict[str, Any]], Any],
218
- Mapping[
219
- str,
220
- Union[Runnable[dict[str, Any], Any], Callable[[dict[str, Any]], Any]],
221
- ],
222
- ],
209
+ **kwargs: Runnable[dict[str, Any], Any]
210
+ | Callable[[dict[str, Any]], Any]
211
+ | Mapping[str, Runnable[dict[str, Any], Any] | Callable[[dict[str, Any]], Any]],
223
212
  ) -> RunnableAssign:
224
213
  """Merge the Dict input with the output produced by the mapping argument.
225
214
 
@@ -235,7 +224,7 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
235
224
 
236
225
  @override
237
226
  def invoke(
238
- self, input: Other, config: Optional[RunnableConfig] = None, **kwargs: Any
227
+ self, input: Other, config: RunnableConfig | None = None, **kwargs: Any
239
228
  ) -> Other:
240
229
  if self.func is not None:
241
230
  call_func_with_variable_args(
@@ -247,8 +236,8 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
247
236
  async def ainvoke(
248
237
  self,
249
238
  input: Other,
250
- config: Optional[RunnableConfig] = None,
251
- **kwargs: Optional[Any],
239
+ config: RunnableConfig | None = None,
240
+ **kwargs: Any | None,
252
241
  ) -> Other:
253
242
  if self.afunc is not None:
254
243
  await acall_func_with_variable_args(
@@ -264,7 +253,7 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
264
253
  def transform(
265
254
  self,
266
255
  input: Iterator[Other],
267
- config: Optional[RunnableConfig] = None,
256
+ config: RunnableConfig | None = None,
268
257
  **kwargs: Any,
269
258
  ) -> Iterator[Other]:
270
259
  if self.func is None:
@@ -295,7 +284,7 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
295
284
  async def atransform(
296
285
  self,
297
286
  input: AsyncIterator[Other],
298
- config: Optional[RunnableConfig] = None,
287
+ config: RunnableConfig | None = None,
299
288
  **kwargs: Any,
300
289
  ) -> AsyncIterator[Other]:
301
290
  if self.afunc is None and self.func is None:
@@ -338,7 +327,7 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
338
327
  def stream(
339
328
  self,
340
329
  input: Other,
341
- config: Optional[RunnableConfig] = None,
330
+ config: RunnableConfig | None = None,
342
331
  **kwargs: Any,
343
332
  ) -> Iterator[Other]:
344
333
  return self.transform(iter([input]), config, **kwargs)
@@ -347,7 +336,7 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
347
336
  async def astream(
348
337
  self,
349
338
  input: Other,
350
- config: Optional[RunnableConfig] = None,
339
+ config: RunnableConfig | None = None,
351
340
  **kwargs: Any,
352
341
  ) -> AsyncIterator[Other]:
353
342
  async def input_aiter() -> AsyncIterator[Other]:
@@ -369,32 +358,35 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
369
358
  on the mapper's logic.
370
359
 
371
360
  Examples:
372
- .. code-block:: python
361
+ ```python
362
+ # This is a RunnableAssign
363
+ from langchain_core.runnables.passthrough import (
364
+ RunnableAssign,
365
+ RunnableParallel,
366
+ )
367
+ from langchain_core.runnables.base import RunnableLambda
373
368
 
374
- # This is a RunnableAssign
375
- from langchain_core.runnables.passthrough import (
376
- RunnableAssign,
377
- RunnableParallel,
378
- )
379
- from langchain_core.runnables.base import RunnableLambda
380
369
 
381
- def add_ten(x: dict[str, int]) -> dict[str, int]:
382
- return {"added": x["input"] + 10}
370
+ def add_ten(x: dict[str, int]) -> dict[str, int]:
371
+ return {"added": x["input"] + 10}
383
372
 
384
- mapper = RunnableParallel(
385
- {"add_step": RunnableLambda(add_ten),}
386
- )
387
373
 
388
- runnable_assign = RunnableAssign(mapper)
374
+ mapper = RunnableParallel(
375
+ {
376
+ "add_step": RunnableLambda(add_ten),
377
+ }
378
+ )
389
379
 
390
- # Synchronous example
391
- runnable_assign.invoke({"input": 5})
392
- # returns {'input': 5, 'add_step': {'added': 15}}
380
+ runnable_assign = RunnableAssign(mapper)
393
381
 
394
- # Asynchronous example
395
- await runnable_assign.ainvoke({"input": 5})
396
- # returns {'input': 5, 'add_step': {'added': 15}}
382
+ # Synchronous example
383
+ runnable_assign.invoke({"input": 5})
384
+ # returns {'input': 5, 'add_step': {'added': 15}}
397
385
 
386
+ # Asynchronous example
387
+ await runnable_assign.ainvoke({"input": 5})
388
+ # returns {'input': 5, 'add_step': {'added': 15}}
389
+ ```
398
390
  """
399
391
 
400
392
  mapper: RunnableParallel
@@ -403,25 +395,29 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
403
395
  """Create a RunnableAssign.
404
396
 
405
397
  Args:
406
- mapper: A ``RunnableParallel`` instance that will be used to transform the
398
+ mapper: A `RunnableParallel` instance that will be used to transform the
407
399
  input dictionary.
408
400
  """
409
- super().__init__(mapper=mapper, **kwargs) # type: ignore[call-arg]
401
+ super().__init__(mapper=mapper, **kwargs)
410
402
 
411
403
  @classmethod
412
404
  @override
413
405
  def is_lc_serializable(cls) -> bool:
406
+ """Return True as this class is serializable."""
414
407
  return True
415
408
 
416
409
  @classmethod
417
410
  @override
418
411
  def get_lc_namespace(cls) -> list[str]:
412
+ """Get the namespace of the LangChain object.
413
+
414
+ Returns:
415
+ `["langchain", "schema", "runnable"]`
416
+ """
419
417
  return ["langchain", "schema", "runnable"]
420
418
 
421
419
  @override
422
- def get_name(
423
- self, suffix: Optional[str] = None, *, name: Optional[str] = None
424
- ) -> str:
420
+ def get_name(self, suffix: str | None = None, *, name: str | None = None) -> str:
425
421
  name = (
426
422
  name
427
423
  or self.name
@@ -430,9 +426,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
430
426
  return super().get_name(suffix, name=name)
431
427
 
432
428
  @override
433
- def get_input_schema(
434
- self, config: Optional[RunnableConfig] = None
435
- ) -> type[BaseModel]:
429
+ def get_input_schema(self, config: RunnableConfig | None = None) -> type[BaseModel]:
436
430
  map_input_schema = self.mapper.get_input_schema(config)
437
431
  if not issubclass(map_input_schema, RootModel):
438
432
  # ie. it's a dict
@@ -442,7 +436,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
442
436
 
443
437
  @override
444
438
  def get_output_schema(
445
- self, config: Optional[RunnableConfig] = None
439
+ self, config: RunnableConfig | None = None
446
440
  ) -> type[BaseModel]:
447
441
  map_input_schema = self.mapper.get_input_schema(config)
448
442
  map_output_schema = self.mapper.get_output_schema(config)
@@ -507,7 +501,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
507
501
  def invoke(
508
502
  self,
509
503
  input: dict[str, Any],
510
- config: Optional[RunnableConfig] = None,
504
+ config: RunnableConfig | None = None,
511
505
  **kwargs: Any,
512
506
  ) -> dict[str, Any]:
513
507
  return self._call_with_config(self._invoke, input, config, **kwargs)
@@ -536,7 +530,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
536
530
  async def ainvoke(
537
531
  self,
538
532
  input: dict[str, Any],
539
- config: Optional[RunnableConfig] = None,
533
+ config: RunnableConfig | None = None,
540
534
  **kwargs: Any,
541
535
  ) -> dict[str, Any]:
542
536
  return await self._acall_with_config(self._ainvoke, input, config, **kwargs)
@@ -591,7 +585,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
591
585
  def transform(
592
586
  self,
593
587
  input: Iterator[dict[str, Any]],
594
- config: Optional[RunnableConfig] = None,
588
+ config: RunnableConfig | None = None,
595
589
  **kwargs: Any | None,
596
590
  ) -> Iterator[dict[str, Any]]:
597
591
  yield from self._transform_stream_with_config(
@@ -643,7 +637,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
643
637
  async def atransform(
644
638
  self,
645
639
  input: AsyncIterator[dict[str, Any]],
646
- config: Optional[RunnableConfig] = None,
640
+ config: RunnableConfig | None = None,
647
641
  **kwargs: Any,
648
642
  ) -> AsyncIterator[dict[str, Any]]:
649
643
  async for chunk in self._atransform_stream_with_config(
@@ -655,7 +649,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
655
649
  def stream(
656
650
  self,
657
651
  input: dict[str, Any],
658
- config: Optional[RunnableConfig] = None,
652
+ config: RunnableConfig | None = None,
659
653
  **kwargs: Any,
660
654
  ) -> Iterator[dict[str, Any]]:
661
655
  return self.transform(iter([input]), config, **kwargs)
@@ -664,7 +658,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
664
658
  async def astream(
665
659
  self,
666
660
  input: dict[str, Any],
667
- config: Optional[RunnableConfig] = None,
661
+ config: RunnableConfig | None = None,
668
662
  **kwargs: Any,
669
663
  ) -> AsyncIterator[dict[str, Any]]:
670
664
  async def input_aiter() -> AsyncIterator[dict[str, Any]]:
@@ -683,54 +677,57 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
683
677
  the selected keys.
684
678
 
685
679
  Example:
686
- .. code-block:: python
687
-
688
- from langchain_core.runnables.passthrough import RunnablePick
689
-
690
- input_data = {
691
- 'name': 'John',
692
- 'age': 30,
693
- 'city': 'New York',
694
- 'country': 'USA'
695
- }
696
-
697
- runnable = RunnablePick(keys=['name', 'age'])
680
+ ```python
681
+ from langchain_core.runnables.passthrough import RunnablePick
682
+
683
+ input_data = {
684
+ "name": "John",
685
+ "age": 30,
686
+ "city": "New York",
687
+ "country": "USA",
688
+ }
698
689
 
699
- output_data = runnable.invoke(input_data)
690
+ runnable = RunnablePick(keys=["name", "age"])
700
691
 
701
- print(output_data) # Output: {'name': 'John', 'age': 30}
692
+ output_data = runnable.invoke(input_data)
702
693
 
694
+ print(output_data) # Output: {'name': 'John', 'age': 30}
695
+ ```
703
696
  """
704
697
 
705
- keys: Union[str, list[str]]
698
+ keys: str | list[str]
706
699
 
707
- def __init__(self, keys: Union[str, list[str]], **kwargs: Any) -> None:
700
+ def __init__(self, keys: str | list[str], **kwargs: Any) -> None:
708
701
  """Create a RunnablePick.
709
702
 
710
703
  Args:
711
704
  keys: A single key or a list of keys to pick from the input dictionary.
712
705
  """
713
- super().__init__(keys=keys, **kwargs) # type: ignore[call-arg]
706
+ super().__init__(keys=keys, **kwargs)
714
707
 
715
708
  @classmethod
716
709
  @override
717
710
  def is_lc_serializable(cls) -> bool:
711
+ """Return True as this class is serializable."""
718
712
  return True
719
713
 
720
714
  @classmethod
721
715
  @override
722
716
  def get_lc_namespace(cls) -> list[str]:
723
- """Get the namespace of the langchain object."""
717
+ """Get the namespace of the LangChain object.
718
+
719
+ Returns:
720
+ `["langchain", "schema", "runnable"]`
721
+ """
724
722
  return ["langchain", "schema", "runnable"]
725
723
 
726
724
  @override
727
- def get_name(
728
- self, suffix: Optional[str] = None, *, name: Optional[str] = None
729
- ) -> str:
725
+ def get_name(self, suffix: str | None = None, *, name: str | None = None) -> str:
730
726
  name = (
731
727
  name
732
728
  or self.name
733
- or f"RunnablePick<{','.join([self.keys] if isinstance(self.keys, str) else self.keys)}>" # noqa: E501
729
+ or "RunnablePick"
730
+ f"<{','.join([self.keys] if isinstance(self.keys, str) else self.keys)}>"
734
731
  )
735
732
  return super().get_name(suffix, name=name)
736
733
 
@@ -756,7 +753,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
756
753
  def invoke(
757
754
  self,
758
755
  input: dict[str, Any],
759
- config: Optional[RunnableConfig] = None,
756
+ config: RunnableConfig | None = None,
760
757
  **kwargs: Any,
761
758
  ) -> dict[str, Any]:
762
759
  return self._call_with_config(self._invoke, input, config, **kwargs)
@@ -771,7 +768,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
771
768
  async def ainvoke(
772
769
  self,
773
770
  input: dict[str, Any],
774
- config: Optional[RunnableConfig] = None,
771
+ config: RunnableConfig | None = None,
775
772
  **kwargs: Any,
776
773
  ) -> dict[str, Any]:
777
774
  return await self._acall_with_config(self._ainvoke, input, config, **kwargs)
@@ -789,7 +786,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
789
786
  def transform(
790
787
  self,
791
788
  input: Iterator[dict[str, Any]],
792
- config: Optional[RunnableConfig] = None,
789
+ config: RunnableConfig | None = None,
793
790
  **kwargs: Any,
794
791
  ) -> Iterator[dict[str, Any]]:
795
792
  yield from self._transform_stream_with_config(
@@ -809,7 +806,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
809
806
  async def atransform(
810
807
  self,
811
808
  input: AsyncIterator[dict[str, Any]],
812
- config: Optional[RunnableConfig] = None,
809
+ config: RunnableConfig | None = None,
813
810
  **kwargs: Any,
814
811
  ) -> AsyncIterator[dict[str, Any]]:
815
812
  async for chunk in self._atransform_stream_with_config(
@@ -821,7 +818,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
821
818
  def stream(
822
819
  self,
823
820
  input: dict[str, Any],
824
- config: Optional[RunnableConfig] = None,
821
+ config: RunnableConfig | None = None,
825
822
  **kwargs: Any,
826
823
  ) -> Iterator[dict[str, Any]]:
827
824
  return self.transform(iter([input]), config, **kwargs)
@@ -830,7 +827,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
830
827
  async def astream(
831
828
  self,
832
829
  input: dict[str, Any],
833
- config: Optional[RunnableConfig] = None,
830
+ config: RunnableConfig | None = None,
834
831
  **kwargs: Any,
835
832
  ) -> AsyncIterator[dict[str, Any]]:
836
833
  async def input_aiter() -> AsyncIterator[dict[str, Any]]: