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.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +3 -4
- langchain_core/_api/beta_decorator.py +45 -70
- langchain_core/_api/deprecation.py +80 -80
- langchain_core/_api/path.py +22 -8
- langchain_core/_import_utils.py +10 -4
- langchain_core/agents.py +25 -21
- langchain_core/caches.py +53 -63
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +341 -348
- langchain_core/callbacks/file.py +55 -44
- langchain_core/callbacks/manager.py +546 -683
- langchain_core/callbacks/stdout.py +29 -30
- langchain_core/callbacks/streaming_stdout.py +35 -36
- langchain_core/callbacks/usage.py +65 -70
- langchain_core/chat_history.py +48 -55
- langchain_core/document_loaders/base.py +46 -21
- langchain_core/document_loaders/langsmith.py +39 -36
- langchain_core/documents/__init__.py +0 -1
- langchain_core/documents/base.py +96 -74
- langchain_core/documents/compressor.py +12 -9
- langchain_core/documents/transformers.py +29 -28
- langchain_core/embeddings/fake.py +56 -57
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/example_selectors/length_based.py +1 -1
- langchain_core/example_selectors/semantic_similarity.py +21 -25
- langchain_core/exceptions.py +15 -9
- langchain_core/globals.py +4 -163
- langchain_core/indexing/api.py +132 -125
- langchain_core/indexing/base.py +64 -67
- langchain_core/indexing/in_memory.py +26 -6
- langchain_core/language_models/__init__.py +15 -27
- langchain_core/language_models/_utils.py +267 -117
- langchain_core/language_models/base.py +92 -177
- langchain_core/language_models/chat_models.py +547 -407
- langchain_core/language_models/fake.py +11 -11
- langchain_core/language_models/fake_chat_models.py +72 -118
- langchain_core/language_models/llms.py +168 -242
- langchain_core/load/dump.py +8 -11
- langchain_core/load/load.py +32 -28
- langchain_core/load/mapping.py +2 -4
- langchain_core/load/serializable.py +50 -56
- langchain_core/messages/__init__.py +36 -51
- langchain_core/messages/ai.py +377 -150
- langchain_core/messages/base.py +239 -47
- langchain_core/messages/block_translators/__init__.py +111 -0
- langchain_core/messages/block_translators/anthropic.py +470 -0
- langchain_core/messages/block_translators/bedrock.py +94 -0
- langchain_core/messages/block_translators/bedrock_converse.py +297 -0
- langchain_core/messages/block_translators/google_genai.py +530 -0
- langchain_core/messages/block_translators/google_vertexai.py +21 -0
- langchain_core/messages/block_translators/groq.py +143 -0
- langchain_core/messages/block_translators/langchain_v0.py +301 -0
- langchain_core/messages/block_translators/openai.py +1010 -0
- langchain_core/messages/chat.py +2 -3
- langchain_core/messages/content.py +1423 -0
- langchain_core/messages/function.py +7 -7
- langchain_core/messages/human.py +44 -38
- langchain_core/messages/modifier.py +3 -2
- langchain_core/messages/system.py +40 -27
- langchain_core/messages/tool.py +160 -58
- langchain_core/messages/utils.py +527 -638
- langchain_core/output_parsers/__init__.py +1 -14
- langchain_core/output_parsers/base.py +68 -104
- langchain_core/output_parsers/json.py +13 -17
- langchain_core/output_parsers/list.py +11 -33
- langchain_core/output_parsers/openai_functions.py +56 -74
- langchain_core/output_parsers/openai_tools.py +68 -109
- langchain_core/output_parsers/pydantic.py +15 -13
- langchain_core/output_parsers/string.py +6 -2
- langchain_core/output_parsers/transform.py +17 -60
- langchain_core/output_parsers/xml.py +34 -44
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +26 -11
- langchain_core/outputs/chat_result.py +1 -3
- langchain_core/outputs/generation.py +17 -6
- langchain_core/outputs/llm_result.py +15 -8
- langchain_core/prompt_values.py +29 -123
- langchain_core/prompts/__init__.py +3 -27
- langchain_core/prompts/base.py +48 -63
- langchain_core/prompts/chat.py +259 -288
- langchain_core/prompts/dict.py +19 -11
- langchain_core/prompts/few_shot.py +84 -90
- langchain_core/prompts/few_shot_with_templates.py +14 -12
- langchain_core/prompts/image.py +19 -14
- langchain_core/prompts/loading.py +6 -8
- langchain_core/prompts/message.py +7 -8
- langchain_core/prompts/prompt.py +42 -43
- langchain_core/prompts/string.py +37 -16
- langchain_core/prompts/structured.py +43 -46
- langchain_core/rate_limiters.py +51 -60
- langchain_core/retrievers.py +52 -192
- langchain_core/runnables/base.py +1727 -1683
- langchain_core/runnables/branch.py +52 -73
- langchain_core/runnables/config.py +89 -103
- langchain_core/runnables/configurable.py +128 -130
- langchain_core/runnables/fallbacks.py +93 -82
- langchain_core/runnables/graph.py +127 -127
- langchain_core/runnables/graph_ascii.py +63 -41
- langchain_core/runnables/graph_mermaid.py +87 -70
- langchain_core/runnables/graph_png.py +31 -36
- langchain_core/runnables/history.py +145 -161
- langchain_core/runnables/passthrough.py +141 -144
- langchain_core/runnables/retry.py +84 -68
- langchain_core/runnables/router.py +33 -37
- langchain_core/runnables/schema.py +79 -72
- langchain_core/runnables/utils.py +95 -139
- langchain_core/stores.py +85 -131
- langchain_core/structured_query.py +11 -15
- langchain_core/sys_info.py +31 -32
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +221 -247
- langchain_core/tools/convert.py +144 -161
- langchain_core/tools/render.py +10 -10
- langchain_core/tools/retriever.py +12 -19
- langchain_core/tools/simple.py +52 -29
- langchain_core/tools/structured.py +56 -60
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/_streaming.py +6 -7
- langchain_core/tracers/base.py +103 -112
- langchain_core/tracers/context.py +29 -48
- langchain_core/tracers/core.py +142 -105
- langchain_core/tracers/evaluation.py +30 -34
- langchain_core/tracers/event_stream.py +162 -117
- langchain_core/tracers/langchain.py +34 -36
- langchain_core/tracers/log_stream.py +87 -49
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +18 -34
- langchain_core/tracers/run_collector.py +8 -20
- langchain_core/tracers/schemas.py +0 -125
- langchain_core/tracers/stdout.py +3 -3
- langchain_core/utils/__init__.py +1 -4
- langchain_core/utils/_merge.py +47 -9
- langchain_core/utils/aiter.py +70 -66
- langchain_core/utils/env.py +12 -9
- langchain_core/utils/function_calling.py +139 -206
- langchain_core/utils/html.py +7 -8
- langchain_core/utils/input.py +6 -6
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +48 -45
- langchain_core/utils/json.py +14 -4
- langchain_core/utils/json_schema.py +159 -43
- langchain_core/utils/mustache.py +32 -25
- langchain_core/utils/pydantic.py +67 -40
- langchain_core/utils/strings.py +5 -5
- langchain_core/utils/usage.py +1 -1
- langchain_core/utils/utils.py +104 -62
- langchain_core/vectorstores/base.py +131 -179
- langchain_core/vectorstores/in_memory.py +113 -182
- langchain_core/vectorstores/utils.py +23 -17
- langchain_core/version.py +1 -1
- langchain_core-1.0.0.dist-info/METADATA +68 -0
- langchain_core-1.0.0.dist-info/RECORD +172 -0
- {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
- langchain_core/beta/__init__.py +0 -1
- langchain_core/beta/runnables/__init__.py +0 -1
- langchain_core/beta/runnables/context.py +0 -448
- langchain_core/memory.py +0 -116
- langchain_core/messages/content_blocks.py +0 -1435
- langchain_core/prompts/pipeline.py +0 -133
- langchain_core/pydantic_v1/__init__.py +0 -30
- langchain_core/pydantic_v1/dataclasses.py +0 -23
- langchain_core/pydantic_v1/main.py +0 -23
- langchain_core/tracers/langchain_v1.py +0 -23
- langchain_core/utils/loading.py +0 -31
- langchain_core/v1/__init__.py +0 -1
- langchain_core/v1/chat_models.py +0 -1047
- langchain_core/v1/messages.py +0 -755
- langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
- langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
- langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
|
@@ -5,8 +5,9 @@ from __future__ import annotations
|
|
|
5
5
|
import ast
|
|
6
6
|
import asyncio
|
|
7
7
|
import inspect
|
|
8
|
+
import sys
|
|
8
9
|
import textwrap
|
|
9
|
-
from collections.abc import Mapping, Sequence
|
|
10
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
10
11
|
from contextvars import Context
|
|
11
12
|
from functools import lru_cache
|
|
12
13
|
from inspect import signature
|
|
@@ -14,15 +15,13 @@ from itertools import groupby
|
|
|
14
15
|
from typing import (
|
|
15
16
|
TYPE_CHECKING,
|
|
16
17
|
Any,
|
|
17
|
-
Callable,
|
|
18
18
|
NamedTuple,
|
|
19
|
-
Optional,
|
|
20
19
|
Protocol,
|
|
20
|
+
TypeGuard,
|
|
21
21
|
TypeVar,
|
|
22
|
-
Union,
|
|
23
22
|
)
|
|
24
23
|
|
|
25
|
-
from typing_extensions import
|
|
24
|
+
from typing_extensions import override
|
|
26
25
|
|
|
27
26
|
# Re-export create-model for backwards compatibility
|
|
28
27
|
from langchain_core.utils.pydantic import create_model # noqa: F401
|
|
@@ -57,7 +56,7 @@ async def gated_coro(semaphore: asyncio.Semaphore, coro: Coroutine) -> Any:
|
|
|
57
56
|
return await coro
|
|
58
57
|
|
|
59
58
|
|
|
60
|
-
async def gather_with_concurrency(n:
|
|
59
|
+
async def gather_with_concurrency(n: int | None, *coros: Coroutine) -> list:
|
|
61
60
|
"""Gather coroutines with a limit on the number of concurrent coroutines.
|
|
62
61
|
|
|
63
62
|
Args:
|
|
@@ -82,7 +81,7 @@ def accepts_run_manager(callable: Callable[..., Any]) -> bool: # noqa: A002
|
|
|
82
81
|
callable: The callable to check.
|
|
83
82
|
|
|
84
83
|
Returns:
|
|
85
|
-
|
|
84
|
+
`True` if the callable accepts a run_manager argument, `False` otherwise.
|
|
86
85
|
"""
|
|
87
86
|
try:
|
|
88
87
|
return signature(callable).parameters.get("run_manager") is not None
|
|
@@ -97,7 +96,7 @@ def accepts_config(callable: Callable[..., Any]) -> bool: # noqa: A002
|
|
|
97
96
|
callable: The callable to check.
|
|
98
97
|
|
|
99
98
|
Returns:
|
|
100
|
-
|
|
99
|
+
`True` if the callable accepts a config argument, `False` otherwise.
|
|
101
100
|
"""
|
|
102
101
|
try:
|
|
103
102
|
return signature(callable).parameters.get("config") is not None
|
|
@@ -112,7 +111,7 @@ def accepts_context(callable: Callable[..., Any]) -> bool: # noqa: A002
|
|
|
112
111
|
callable: The callable to check.
|
|
113
112
|
|
|
114
113
|
Returns:
|
|
115
|
-
|
|
114
|
+
`True` if the callable accepts a context argument, `False` otherwise.
|
|
116
115
|
"""
|
|
117
116
|
try:
|
|
118
117
|
return signature(callable).parameters.get("context") is not None
|
|
@@ -120,10 +119,13 @@ def accepts_context(callable: Callable[..., Any]) -> bool: # noqa: A002
|
|
|
120
119
|
return False
|
|
121
120
|
|
|
122
121
|
|
|
123
|
-
@lru_cache(maxsize=1)
|
|
124
122
|
def asyncio_accepts_context() -> bool:
|
|
125
|
-
"""
|
|
126
|
-
|
|
123
|
+
"""Check if asyncio.create_task accepts a `context` arg.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
True if `asyncio.create_task` accepts a context argument, `False` otherwise.
|
|
127
|
+
"""
|
|
128
|
+
return sys.version_info >= (3, 11)
|
|
127
129
|
|
|
128
130
|
|
|
129
131
|
def coro_with_context(
|
|
@@ -134,7 +136,7 @@ def coro_with_context(
|
|
|
134
136
|
Args:
|
|
135
137
|
coro: The coroutine to await.
|
|
136
138
|
context: The context to use.
|
|
137
|
-
create_task: Whether to create a task.
|
|
139
|
+
create_task: Whether to create a task.
|
|
138
140
|
|
|
139
141
|
Returns:
|
|
140
142
|
The coroutine with the context.
|
|
@@ -160,14 +162,11 @@ class IsLocalDict(ast.NodeVisitor):
|
|
|
160
162
|
self.keys = keys
|
|
161
163
|
|
|
162
164
|
@override
|
|
163
|
-
def visit_Subscript(self, node: ast.Subscript) ->
|
|
165
|
+
def visit_Subscript(self, node: ast.Subscript) -> None:
|
|
164
166
|
"""Visit a subscript node.
|
|
165
167
|
|
|
166
168
|
Args:
|
|
167
169
|
node: The node to visit.
|
|
168
|
-
|
|
169
|
-
Returns:
|
|
170
|
-
Any: The result of the visit.
|
|
171
170
|
"""
|
|
172
171
|
if (
|
|
173
172
|
isinstance(node.ctx, ast.Load)
|
|
@@ -180,14 +179,11 @@ class IsLocalDict(ast.NodeVisitor):
|
|
|
180
179
|
self.keys.add(node.slice.value)
|
|
181
180
|
|
|
182
181
|
@override
|
|
183
|
-
def visit_Call(self, node: ast.Call) ->
|
|
182
|
+
def visit_Call(self, node: ast.Call) -> None:
|
|
184
183
|
"""Visit a call node.
|
|
185
184
|
|
|
186
185
|
Args:
|
|
187
186
|
node: The node to visit.
|
|
188
|
-
|
|
189
|
-
Returns:
|
|
190
|
-
Any: The result of the visit.
|
|
191
187
|
"""
|
|
192
188
|
if (
|
|
193
189
|
isinstance(node.func, ast.Attribute)
|
|
@@ -210,14 +206,11 @@ class IsFunctionArgDict(ast.NodeVisitor):
|
|
|
210
206
|
self.keys: set[str] = set()
|
|
211
207
|
|
|
212
208
|
@override
|
|
213
|
-
def visit_Lambda(self, node: ast.Lambda) ->
|
|
209
|
+
def visit_Lambda(self, node: ast.Lambda) -> None:
|
|
214
210
|
"""Visit a lambda function.
|
|
215
211
|
|
|
216
212
|
Args:
|
|
217
213
|
node: The node to visit.
|
|
218
|
-
|
|
219
|
-
Returns:
|
|
220
|
-
Any: The result of the visit.
|
|
221
214
|
"""
|
|
222
215
|
if not node.args.args:
|
|
223
216
|
return
|
|
@@ -225,14 +218,11 @@ class IsFunctionArgDict(ast.NodeVisitor):
|
|
|
225
218
|
IsLocalDict(input_arg_name, self.keys).visit(node.body)
|
|
226
219
|
|
|
227
220
|
@override
|
|
228
|
-
def visit_FunctionDef(self, node: ast.FunctionDef) ->
|
|
221
|
+
def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
|
|
229
222
|
"""Visit a function definition.
|
|
230
223
|
|
|
231
224
|
Args:
|
|
232
225
|
node: The node to visit.
|
|
233
|
-
|
|
234
|
-
Returns:
|
|
235
|
-
Any: The result of the visit.
|
|
236
226
|
"""
|
|
237
227
|
if not node.args.args:
|
|
238
228
|
return
|
|
@@ -240,14 +230,11 @@ class IsFunctionArgDict(ast.NodeVisitor):
|
|
|
240
230
|
IsLocalDict(input_arg_name, self.keys).visit(node)
|
|
241
231
|
|
|
242
232
|
@override
|
|
243
|
-
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) ->
|
|
233
|
+
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
|
|
244
234
|
"""Visit an async function definition.
|
|
245
235
|
|
|
246
236
|
Args:
|
|
247
237
|
node: The node to visit.
|
|
248
|
-
|
|
249
|
-
Returns:
|
|
250
|
-
Any: The result of the visit.
|
|
251
238
|
"""
|
|
252
239
|
if not node.args.args:
|
|
253
240
|
return
|
|
@@ -264,14 +251,11 @@ class NonLocals(ast.NodeVisitor):
|
|
|
264
251
|
self.stores: set[str] = set()
|
|
265
252
|
|
|
266
253
|
@override
|
|
267
|
-
def visit_Name(self, node: ast.Name) ->
|
|
254
|
+
def visit_Name(self, node: ast.Name) -> None:
|
|
268
255
|
"""Visit a name node.
|
|
269
256
|
|
|
270
257
|
Args:
|
|
271
258
|
node: The node to visit.
|
|
272
|
-
|
|
273
|
-
Returns:
|
|
274
|
-
Any: The result of the visit.
|
|
275
259
|
"""
|
|
276
260
|
if isinstance(node.ctx, ast.Load):
|
|
277
261
|
self.loads.add(node.id)
|
|
@@ -279,14 +263,11 @@ class NonLocals(ast.NodeVisitor):
|
|
|
279
263
|
self.stores.add(node.id)
|
|
280
264
|
|
|
281
265
|
@override
|
|
282
|
-
def visit_Attribute(self, node: ast.Attribute) ->
|
|
266
|
+
def visit_Attribute(self, node: ast.Attribute) -> None:
|
|
283
267
|
"""Visit an attribute node.
|
|
284
268
|
|
|
285
269
|
Args:
|
|
286
270
|
node: The node to visit.
|
|
287
|
-
|
|
288
|
-
Returns:
|
|
289
|
-
Any: The result of the visit.
|
|
290
271
|
"""
|
|
291
272
|
if isinstance(node.ctx, ast.Load):
|
|
292
273
|
parent = node.value
|
|
@@ -321,42 +302,33 @@ class FunctionNonLocals(ast.NodeVisitor):
|
|
|
321
302
|
self.nonlocals: set[str] = set()
|
|
322
303
|
|
|
323
304
|
@override
|
|
324
|
-
def visit_FunctionDef(self, node: ast.FunctionDef) ->
|
|
305
|
+
def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
|
|
325
306
|
"""Visit a function definition.
|
|
326
307
|
|
|
327
308
|
Args:
|
|
328
309
|
node: The node to visit.
|
|
329
|
-
|
|
330
|
-
Returns:
|
|
331
|
-
Any: The result of the visit.
|
|
332
310
|
"""
|
|
333
311
|
visitor = NonLocals()
|
|
334
312
|
visitor.visit(node)
|
|
335
313
|
self.nonlocals.update(visitor.loads - visitor.stores)
|
|
336
314
|
|
|
337
315
|
@override
|
|
338
|
-
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) ->
|
|
316
|
+
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
|
|
339
317
|
"""Visit an async function definition.
|
|
340
318
|
|
|
341
319
|
Args:
|
|
342
320
|
node: The node to visit.
|
|
343
|
-
|
|
344
|
-
Returns:
|
|
345
|
-
Any: The result of the visit.
|
|
346
321
|
"""
|
|
347
322
|
visitor = NonLocals()
|
|
348
323
|
visitor.visit(node)
|
|
349
324
|
self.nonlocals.update(visitor.loads - visitor.stores)
|
|
350
325
|
|
|
351
326
|
@override
|
|
352
|
-
def visit_Lambda(self, node: ast.Lambda) ->
|
|
327
|
+
def visit_Lambda(self, node: ast.Lambda) -> None:
|
|
353
328
|
"""Visit a lambda function.
|
|
354
329
|
|
|
355
330
|
Args:
|
|
356
331
|
node: The node to visit.
|
|
357
|
-
|
|
358
|
-
Returns:
|
|
359
|
-
Any: The result of the visit.
|
|
360
332
|
"""
|
|
361
333
|
visitor = NonLocals()
|
|
362
334
|
visitor.visit(node)
|
|
@@ -368,33 +340,29 @@ class GetLambdaSource(ast.NodeVisitor):
|
|
|
368
340
|
|
|
369
341
|
def __init__(self) -> None:
|
|
370
342
|
"""Initialize the visitor."""
|
|
371
|
-
self.source:
|
|
343
|
+
self.source: str | None = None
|
|
372
344
|
self.count = 0
|
|
373
345
|
|
|
374
346
|
@override
|
|
375
|
-
def visit_Lambda(self, node: ast.Lambda) ->
|
|
347
|
+
def visit_Lambda(self, node: ast.Lambda) -> None:
|
|
376
348
|
"""Visit a lambda function.
|
|
377
349
|
|
|
378
350
|
Args:
|
|
379
351
|
node: The node to visit.
|
|
380
|
-
|
|
381
|
-
Returns:
|
|
382
|
-
Any: The result of the visit.
|
|
383
352
|
"""
|
|
384
353
|
self.count += 1
|
|
385
354
|
if hasattr(ast, "unparse"):
|
|
386
355
|
self.source = ast.unparse(node)
|
|
387
356
|
|
|
388
357
|
|
|
389
|
-
def get_function_first_arg_dict_keys(func: Callable) ->
|
|
358
|
+
def get_function_first_arg_dict_keys(func: Callable) -> list[str] | None:
|
|
390
359
|
"""Get the keys of the first argument of a function if it is a dict.
|
|
391
360
|
|
|
392
361
|
Args:
|
|
393
362
|
func: The function to check.
|
|
394
363
|
|
|
395
364
|
Returns:
|
|
396
|
-
|
|
397
|
-
None otherwise.
|
|
365
|
+
The keys of the first argument if it is a dict, None otherwise.
|
|
398
366
|
"""
|
|
399
367
|
try:
|
|
400
368
|
code = inspect.getsource(func)
|
|
@@ -406,14 +374,14 @@ def get_function_first_arg_dict_keys(func: Callable) -> Optional[list[str]]:
|
|
|
406
374
|
return None
|
|
407
375
|
|
|
408
376
|
|
|
409
|
-
def get_lambda_source(func: Callable) ->
|
|
377
|
+
def get_lambda_source(func: Callable) -> str | None:
|
|
410
378
|
"""Get the source code of a lambda function.
|
|
411
379
|
|
|
412
380
|
Args:
|
|
413
381
|
func: a Callable that can be a lambda function.
|
|
414
382
|
|
|
415
383
|
Returns:
|
|
416
|
-
|
|
384
|
+
the source code of the lambda function.
|
|
417
385
|
"""
|
|
418
386
|
try:
|
|
419
387
|
name = func.__name__ if func.__name__ != "<lambda>" else None
|
|
@@ -437,7 +405,7 @@ def get_function_nonlocals(func: Callable) -> list[Any]:
|
|
|
437
405
|
func: The function to check.
|
|
438
406
|
|
|
439
407
|
Returns:
|
|
440
|
-
|
|
408
|
+
The nonlocal variables accessed by the function.
|
|
441
409
|
"""
|
|
442
410
|
try:
|
|
443
411
|
code = inspect.getsource(func)
|
|
@@ -480,7 +448,7 @@ def indent_lines_after_first(text: str, prefix: str) -> str:
|
|
|
480
448
|
prefix: Used to determine the number of spaces to indent.
|
|
481
449
|
|
|
482
450
|
Returns:
|
|
483
|
-
|
|
451
|
+
The indented text.
|
|
484
452
|
"""
|
|
485
453
|
n_spaces = len(prefix)
|
|
486
454
|
spaces = " " * n_spaces
|
|
@@ -496,6 +464,9 @@ class AddableDict(dict[str, Any]):
|
|
|
496
464
|
|
|
497
465
|
Args:
|
|
498
466
|
other: The other dictionary to add.
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
A dictionary that is the result of adding the two dictionaries.
|
|
499
470
|
"""
|
|
500
471
|
chunk = AddableDict(self)
|
|
501
472
|
for key in other:
|
|
@@ -514,6 +485,9 @@ class AddableDict(dict[str, Any]):
|
|
|
514
485
|
|
|
515
486
|
Args:
|
|
516
487
|
other: The other dictionary to be added to.
|
|
488
|
+
|
|
489
|
+
Returns:
|
|
490
|
+
A dictionary that is the result of adding the two dictionaries.
|
|
517
491
|
"""
|
|
518
492
|
chunk = AddableDict(other)
|
|
519
493
|
for key in self:
|
|
@@ -542,53 +516,49 @@ class SupportsAdd(Protocol[_T_contra, _T_co]):
|
|
|
542
516
|
Addable = TypeVar("Addable", bound=SupportsAdd[Any, Any])
|
|
543
517
|
|
|
544
518
|
|
|
545
|
-
def add(addables: Iterable[Addable]) ->
|
|
519
|
+
def add(addables: Iterable[Addable]) -> Addable | None:
|
|
546
520
|
"""Add a sequence of addable objects together.
|
|
547
521
|
|
|
548
522
|
Args:
|
|
549
523
|
addables: The addable objects to add.
|
|
550
524
|
|
|
551
525
|
Returns:
|
|
552
|
-
|
|
526
|
+
The result of adding the addable objects.
|
|
553
527
|
"""
|
|
554
|
-
final:
|
|
528
|
+
final: Addable | None = None
|
|
555
529
|
for chunk in addables:
|
|
556
530
|
final = chunk if final is None else final + chunk
|
|
557
531
|
return final
|
|
558
532
|
|
|
559
533
|
|
|
560
|
-
async def aadd(addables: AsyncIterable[Addable]) ->
|
|
534
|
+
async def aadd(addables: AsyncIterable[Addable]) -> Addable | None:
|
|
561
535
|
"""Asynchronously add a sequence of addable objects together.
|
|
562
536
|
|
|
563
537
|
Args:
|
|
564
538
|
addables: The addable objects to add.
|
|
565
539
|
|
|
566
540
|
Returns:
|
|
567
|
-
|
|
541
|
+
The result of adding the addable objects.
|
|
568
542
|
"""
|
|
569
|
-
final:
|
|
543
|
+
final: Addable | None = None
|
|
570
544
|
async for chunk in addables:
|
|
571
545
|
final = chunk if final is None else final + chunk
|
|
572
546
|
return final
|
|
573
547
|
|
|
574
548
|
|
|
575
549
|
class ConfigurableField(NamedTuple):
|
|
576
|
-
"""Field that can be configured by the user.
|
|
577
|
-
|
|
578
|
-
Parameters:
|
|
579
|
-
id: The unique identifier of the field.
|
|
580
|
-
name: The name of the field. Defaults to None.
|
|
581
|
-
description: The description of the field. Defaults to None.
|
|
582
|
-
annotation: The annotation of the field. Defaults to None.
|
|
583
|
-
is_shared: Whether the field is shared. Defaults to False.
|
|
584
|
-
"""
|
|
550
|
+
"""Field that can be configured by the user."""
|
|
585
551
|
|
|
586
552
|
id: str
|
|
587
|
-
|
|
588
|
-
name:
|
|
589
|
-
|
|
590
|
-
|
|
553
|
+
"""The unique identifier of the field."""
|
|
554
|
+
name: str | None = None
|
|
555
|
+
"""The name of the field. """
|
|
556
|
+
description: str | None = None
|
|
557
|
+
"""The description of the field. """
|
|
558
|
+
annotation: Any | None = None
|
|
559
|
+
"""The annotation of the field. """
|
|
591
560
|
is_shared: bool = False
|
|
561
|
+
"""Whether the field is shared."""
|
|
592
562
|
|
|
593
563
|
@override
|
|
594
564
|
def __hash__(self) -> int:
|
|
@@ -596,24 +566,20 @@ class ConfigurableField(NamedTuple):
|
|
|
596
566
|
|
|
597
567
|
|
|
598
568
|
class ConfigurableFieldSingleOption(NamedTuple):
|
|
599
|
-
"""Field that can be configured by the user with a default value.
|
|
600
|
-
|
|
601
|
-
Parameters:
|
|
602
|
-
id: The unique identifier of the field.
|
|
603
|
-
options: The options for the field.
|
|
604
|
-
default: The default value for the field.
|
|
605
|
-
name: The name of the field. Defaults to None.
|
|
606
|
-
description: The description of the field. Defaults to None.
|
|
607
|
-
is_shared: Whether the field is shared. Defaults to False.
|
|
608
|
-
"""
|
|
569
|
+
"""Field that can be configured by the user with a default value."""
|
|
609
570
|
|
|
610
571
|
id: str
|
|
572
|
+
"""The unique identifier of the field."""
|
|
611
573
|
options: Mapping[str, Any]
|
|
574
|
+
"""The options for the field."""
|
|
612
575
|
default: str
|
|
613
|
-
|
|
614
|
-
name:
|
|
615
|
-
|
|
576
|
+
"""The default value for the field."""
|
|
577
|
+
name: str | None = None
|
|
578
|
+
"""The name of the field. """
|
|
579
|
+
description: str | None = None
|
|
580
|
+
"""The description of the field. """
|
|
616
581
|
is_shared: bool = False
|
|
582
|
+
"""Whether the field is shared."""
|
|
617
583
|
|
|
618
584
|
@override
|
|
619
585
|
def __hash__(self) -> int:
|
|
@@ -621,56 +587,48 @@ class ConfigurableFieldSingleOption(NamedTuple):
|
|
|
621
587
|
|
|
622
588
|
|
|
623
589
|
class ConfigurableFieldMultiOption(NamedTuple):
|
|
624
|
-
"""Field that can be configured by the user with multiple default values.
|
|
625
|
-
|
|
626
|
-
Parameters:
|
|
627
|
-
id: The unique identifier of the field.
|
|
628
|
-
options: The options for the field.
|
|
629
|
-
default: The default values for the field.
|
|
630
|
-
name: The name of the field. Defaults to None.
|
|
631
|
-
description: The description of the field. Defaults to None.
|
|
632
|
-
is_shared: Whether the field is shared. Defaults to False.
|
|
633
|
-
"""
|
|
590
|
+
"""Field that can be configured by the user with multiple default values."""
|
|
634
591
|
|
|
635
592
|
id: str
|
|
593
|
+
"""The unique identifier of the field."""
|
|
636
594
|
options: Mapping[str, Any]
|
|
595
|
+
"""The options for the field."""
|
|
637
596
|
default: Sequence[str]
|
|
638
|
-
|
|
639
|
-
name:
|
|
640
|
-
|
|
597
|
+
"""The default values for the field."""
|
|
598
|
+
name: str | None = None
|
|
599
|
+
"""The name of the field. """
|
|
600
|
+
description: str | None = None
|
|
601
|
+
"""The description of the field. """
|
|
641
602
|
is_shared: bool = False
|
|
603
|
+
"""Whether the field is shared."""
|
|
642
604
|
|
|
643
605
|
@override
|
|
644
606
|
def __hash__(self) -> int:
|
|
645
607
|
return hash((self.id, tuple(self.options.keys()), tuple(self.default)))
|
|
646
608
|
|
|
647
609
|
|
|
648
|
-
AnyConfigurableField =
|
|
649
|
-
ConfigurableField
|
|
650
|
-
|
|
610
|
+
AnyConfigurableField = (
|
|
611
|
+
ConfigurableField | ConfigurableFieldSingleOption | ConfigurableFieldMultiOption
|
|
612
|
+
)
|
|
651
613
|
|
|
652
614
|
|
|
653
615
|
class ConfigurableFieldSpec(NamedTuple):
|
|
654
|
-
"""Field that can be configured by the user. It is a specification of a field.
|
|
655
|
-
|
|
656
|
-
Parameters:
|
|
657
|
-
id: The unique identifier of the field.
|
|
658
|
-
annotation: The annotation of the field.
|
|
659
|
-
name: The name of the field. Defaults to None.
|
|
660
|
-
description: The description of the field. Defaults to None.
|
|
661
|
-
default: The default value for the field. Defaults to None.
|
|
662
|
-
is_shared: Whether the field is shared. Defaults to False.
|
|
663
|
-
dependencies: The dependencies of the field. Defaults to None.
|
|
664
|
-
"""
|
|
616
|
+
"""Field that can be configured by the user. It is a specification of a field."""
|
|
665
617
|
|
|
666
618
|
id: str
|
|
619
|
+
"""The unique identifier of the field."""
|
|
667
620
|
annotation: Any
|
|
668
|
-
|
|
669
|
-
name:
|
|
670
|
-
|
|
621
|
+
"""The annotation of the field."""
|
|
622
|
+
name: str | None = None
|
|
623
|
+
"""The name of the field. """
|
|
624
|
+
description: str | None = None
|
|
625
|
+
"""The description of the field. """
|
|
671
626
|
default: Any = None
|
|
627
|
+
"""The default value for the field. """
|
|
672
628
|
is_shared: bool = False
|
|
673
|
-
|
|
629
|
+
"""Whether the field is shared."""
|
|
630
|
+
dependencies: list[str] | None = None
|
|
631
|
+
"""The dependencies of the field. """
|
|
674
632
|
|
|
675
633
|
|
|
676
634
|
def get_unique_config_specs(
|
|
@@ -682,7 +640,7 @@ def get_unique_config_specs(
|
|
|
682
640
|
specs: The config specs.
|
|
683
641
|
|
|
684
642
|
Returns:
|
|
685
|
-
|
|
643
|
+
The unique config specs.
|
|
686
644
|
|
|
687
645
|
Raises:
|
|
688
646
|
ValueError: If the runnable sequence contains conflicting config specs.
|
|
@@ -709,12 +667,12 @@ class _RootEventFilter:
|
|
|
709
667
|
def __init__(
|
|
710
668
|
self,
|
|
711
669
|
*,
|
|
712
|
-
include_names:
|
|
713
|
-
include_types:
|
|
714
|
-
include_tags:
|
|
715
|
-
exclude_names:
|
|
716
|
-
exclude_types:
|
|
717
|
-
exclude_tags:
|
|
670
|
+
include_names: Sequence[str] | None = None,
|
|
671
|
+
include_types: Sequence[str] | None = None,
|
|
672
|
+
include_tags: Sequence[str] | None = None,
|
|
673
|
+
exclude_names: Sequence[str] | None = None,
|
|
674
|
+
exclude_types: Sequence[str] | None = None,
|
|
675
|
+
exclude_tags: Sequence[str] | None = None,
|
|
718
676
|
) -> None:
|
|
719
677
|
"""Utility to filter the root event in the astream_events implementation.
|
|
720
678
|
|
|
@@ -769,8 +727,7 @@ def is_async_generator(
|
|
|
769
727
|
func: The function to check.
|
|
770
728
|
|
|
771
729
|
Returns:
|
|
772
|
-
|
|
773
|
-
an async generator, False otherwise.
|
|
730
|
+
`True` if the function is an async generator, `False` otherwise.
|
|
774
731
|
"""
|
|
775
732
|
return inspect.isasyncgenfunction(func) or (
|
|
776
733
|
hasattr(func, "__call__") # noqa: B004
|
|
@@ -787,8 +744,7 @@ def is_async_callable(
|
|
|
787
744
|
func: The function to check.
|
|
788
745
|
|
|
789
746
|
Returns:
|
|
790
|
-
|
|
791
|
-
False otherwise.
|
|
747
|
+
`True` if the function is async, `False` otherwise.
|
|
792
748
|
"""
|
|
793
749
|
return asyncio.iscoroutinefunction(func) or (
|
|
794
750
|
hasattr(func, "__call__") # noqa: B004
|