langchain-core 1.0.0a5__py3-none-any.whl → 1.0.3__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.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +3 -4
- langchain_core/_api/beta_decorator.py +23 -26
- langchain_core/_api/deprecation.py +51 -64
- langchain_core/_api/path.py +3 -6
- langchain_core/_import_utils.py +3 -4
- langchain_core/agents.py +20 -22
- langchain_core/caches.py +65 -66
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +321 -336
- langchain_core/callbacks/file.py +44 -44
- langchain_core/callbacks/manager.py +436 -513
- langchain_core/callbacks/stdout.py +29 -30
- langchain_core/callbacks/streaming_stdout.py +32 -32
- langchain_core/callbacks/usage.py +60 -57
- langchain_core/chat_history.py +53 -68
- langchain_core/document_loaders/base.py +27 -25
- langchain_core/document_loaders/blob_loaders.py +1 -1
- langchain_core/document_loaders/langsmith.py +44 -48
- langchain_core/documents/__init__.py +23 -3
- langchain_core/documents/base.py +98 -90
- langchain_core/documents/compressor.py +10 -10
- langchain_core/documents/transformers.py +34 -35
- langchain_core/embeddings/fake.py +50 -54
- langchain_core/example_selectors/length_based.py +1 -1
- langchain_core/example_selectors/semantic_similarity.py +28 -32
- langchain_core/exceptions.py +21 -20
- langchain_core/globals.py +3 -151
- langchain_core/indexing/__init__.py +1 -1
- langchain_core/indexing/api.py +121 -126
- langchain_core/indexing/base.py +73 -75
- langchain_core/indexing/in_memory.py +4 -6
- langchain_core/language_models/__init__.py +14 -29
- langchain_core/language_models/_utils.py +58 -61
- langchain_core/language_models/base.py +53 -162
- langchain_core/language_models/chat_models.py +298 -387
- langchain_core/language_models/fake.py +11 -11
- langchain_core/language_models/fake_chat_models.py +42 -36
- langchain_core/language_models/llms.py +125 -235
- langchain_core/load/dump.py +9 -12
- langchain_core/load/load.py +18 -28
- langchain_core/load/mapping.py +2 -4
- langchain_core/load/serializable.py +42 -40
- langchain_core/messages/__init__.py +10 -16
- langchain_core/messages/ai.py +148 -148
- langchain_core/messages/base.py +58 -52
- langchain_core/messages/block_translators/__init__.py +27 -17
- langchain_core/messages/block_translators/anthropic.py +6 -6
- langchain_core/messages/block_translators/bedrock_converse.py +5 -5
- langchain_core/messages/block_translators/google_genai.py +505 -20
- langchain_core/messages/block_translators/google_vertexai.py +4 -32
- langchain_core/messages/block_translators/groq.py +117 -21
- langchain_core/messages/block_translators/langchain_v0.py +5 -5
- langchain_core/messages/block_translators/openai.py +11 -11
- langchain_core/messages/chat.py +2 -6
- langchain_core/messages/content.py +337 -328
- langchain_core/messages/function.py +6 -10
- langchain_core/messages/human.py +24 -31
- langchain_core/messages/modifier.py +2 -2
- langchain_core/messages/system.py +19 -29
- langchain_core/messages/tool.py +74 -90
- langchain_core/messages/utils.py +474 -504
- langchain_core/output_parsers/__init__.py +13 -10
- langchain_core/output_parsers/base.py +61 -61
- langchain_core/output_parsers/format_instructions.py +9 -4
- langchain_core/output_parsers/json.py +12 -10
- langchain_core/output_parsers/list.py +21 -23
- langchain_core/output_parsers/openai_functions.py +49 -47
- langchain_core/output_parsers/openai_tools.py +16 -21
- langchain_core/output_parsers/pydantic.py +13 -14
- langchain_core/output_parsers/string.py +5 -5
- langchain_core/output_parsers/transform.py +15 -17
- langchain_core/output_parsers/xml.py +35 -34
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +18 -18
- langchain_core/outputs/chat_result.py +1 -3
- langchain_core/outputs/generation.py +10 -11
- langchain_core/outputs/llm_result.py +10 -10
- langchain_core/prompt_values.py +11 -17
- langchain_core/prompts/__init__.py +3 -27
- langchain_core/prompts/base.py +48 -56
- langchain_core/prompts/chat.py +275 -325
- langchain_core/prompts/dict.py +5 -5
- langchain_core/prompts/few_shot.py +81 -88
- langchain_core/prompts/few_shot_with_templates.py +11 -13
- langchain_core/prompts/image.py +12 -14
- langchain_core/prompts/loading.py +4 -6
- langchain_core/prompts/message.py +3 -3
- langchain_core/prompts/prompt.py +24 -39
- langchain_core/prompts/string.py +26 -10
- langchain_core/prompts/structured.py +49 -53
- langchain_core/rate_limiters.py +51 -60
- langchain_core/retrievers.py +61 -198
- langchain_core/runnables/base.py +1478 -1630
- langchain_core/runnables/branch.py +53 -57
- langchain_core/runnables/config.py +72 -89
- langchain_core/runnables/configurable.py +120 -137
- langchain_core/runnables/fallbacks.py +83 -79
- langchain_core/runnables/graph.py +91 -97
- langchain_core/runnables/graph_ascii.py +27 -28
- langchain_core/runnables/graph_mermaid.py +38 -50
- langchain_core/runnables/graph_png.py +15 -16
- langchain_core/runnables/history.py +135 -148
- langchain_core/runnables/passthrough.py +124 -150
- langchain_core/runnables/retry.py +46 -51
- langchain_core/runnables/router.py +25 -30
- langchain_core/runnables/schema.py +75 -80
- langchain_core/runnables/utils.py +60 -67
- langchain_core/stores.py +85 -121
- langchain_core/structured_query.py +8 -8
- langchain_core/sys_info.py +27 -29
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +285 -229
- langchain_core/tools/convert.py +160 -155
- langchain_core/tools/render.py +10 -10
- langchain_core/tools/retriever.py +12 -11
- langchain_core/tools/simple.py +19 -24
- langchain_core/tools/structured.py +32 -39
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/base.py +97 -99
- langchain_core/tracers/context.py +29 -52
- langchain_core/tracers/core.py +49 -53
- langchain_core/tracers/evaluation.py +11 -11
- langchain_core/tracers/event_stream.py +65 -64
- langchain_core/tracers/langchain.py +21 -21
- langchain_core/tracers/log_stream.py +45 -45
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +16 -16
- langchain_core/tracers/run_collector.py +2 -4
- langchain_core/tracers/schemas.py +0 -129
- langchain_core/tracers/stdout.py +3 -3
- langchain_core/utils/__init__.py +1 -4
- langchain_core/utils/_merge.py +2 -2
- langchain_core/utils/aiter.py +57 -61
- langchain_core/utils/env.py +9 -9
- langchain_core/utils/function_calling.py +89 -186
- langchain_core/utils/html.py +7 -8
- langchain_core/utils/input.py +6 -6
- langchain_core/utils/interactive_env.py +1 -1
- langchain_core/utils/iter.py +36 -40
- langchain_core/utils/json.py +4 -3
- langchain_core/utils/json_schema.py +9 -9
- langchain_core/utils/mustache.py +8 -10
- langchain_core/utils/pydantic.py +33 -35
- langchain_core/utils/strings.py +6 -9
- langchain_core/utils/usage.py +1 -1
- langchain_core/utils/utils.py +66 -62
- langchain_core/vectorstores/base.py +182 -216
- langchain_core/vectorstores/in_memory.py +101 -176
- langchain_core/vectorstores/utils.py +5 -5
- langchain_core/version.py +1 -1
- langchain_core-1.0.3.dist-info/METADATA +69 -0
- langchain_core-1.0.3.dist-info/RECORD +172 -0
- {langchain_core-1.0.0a5.dist-info → langchain_core-1.0.3.dist-info}/WHEEL +1 -1
- langchain_core/memory.py +0 -120
- langchain_core/messages/block_translators/ollama.py +0 -47
- langchain_core/prompts/pipeline.py +0 -138
- 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 -31
- langchain_core/utils/loading.py +0 -35
- langchain_core-1.0.0a5.dist-info/METADATA +0 -77
- langchain_core-1.0.0a5.dist-info/RECORD +0 -181
- langchain_core-1.0.0a5.dist-info/entry_points.txt +0 -4
langchain_core/utils/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Utility functions for LangChain.
|
|
2
2
|
|
|
3
3
|
These functions do not depend on any other LangChain module.
|
|
4
4
|
"""
|
|
@@ -21,7 +21,6 @@ if TYPE_CHECKING:
|
|
|
21
21
|
print_text,
|
|
22
22
|
)
|
|
23
23
|
from langchain_core.utils.iter import batch_iterate
|
|
24
|
-
from langchain_core.utils.loading import try_load_from_hub
|
|
25
24
|
from langchain_core.utils.pydantic import pre_init
|
|
26
25
|
from langchain_core.utils.strings import (
|
|
27
26
|
comma_list,
|
|
@@ -68,7 +67,6 @@ __all__ = (
|
|
|
68
67
|
"secret_from_env",
|
|
69
68
|
"stringify_dict",
|
|
70
69
|
"stringify_value",
|
|
71
|
-
"try_load_from_hub",
|
|
72
70
|
"xor_args",
|
|
73
71
|
)
|
|
74
72
|
|
|
@@ -84,7 +82,6 @@ _dynamic_imports = {
|
|
|
84
82
|
"get_colored_text": "input",
|
|
85
83
|
"print_text": "input",
|
|
86
84
|
"batch_iterate": "iter",
|
|
87
|
-
"try_load_from_hub": "loading",
|
|
88
85
|
"pre_init": "pydantic",
|
|
89
86
|
"comma_list": "strings",
|
|
90
87
|
"sanitize_for_postgres": "strings",
|
langchain_core/utils/_merge.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def merge_dicts(left: dict[str, Any], *others: dict[str, Any]) -> dict[str, Any]:
|
|
@@ -80,7 +80,7 @@ def merge_dicts(left: dict[str, Any], *others: dict[str, Any]) -> dict[str, Any]
|
|
|
80
80
|
return merged
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
def merge_lists(left:
|
|
83
|
+
def merge_lists(left: list | None, *others: list | None) -> list | None:
|
|
84
84
|
"""Add many lists, handling None.
|
|
85
85
|
|
|
86
86
|
Args:
|
langchain_core/utils/aiter.py
CHANGED
|
@@ -11,17 +11,15 @@ from collections.abc import (
|
|
|
11
11
|
AsyncIterable,
|
|
12
12
|
AsyncIterator,
|
|
13
13
|
Awaitable,
|
|
14
|
+
Callable,
|
|
14
15
|
Iterator,
|
|
15
16
|
)
|
|
16
17
|
from contextlib import AbstractAsyncContextManager
|
|
17
18
|
from types import TracebackType
|
|
18
19
|
from typing import (
|
|
19
20
|
Any,
|
|
20
|
-
Callable,
|
|
21
21
|
Generic,
|
|
22
|
-
Optional,
|
|
23
22
|
TypeVar,
|
|
24
|
-
Union,
|
|
25
23
|
cast,
|
|
26
24
|
overload,
|
|
27
25
|
)
|
|
@@ -36,8 +34,8 @@ _no_default = object()
|
|
|
36
34
|
# https://github.com/python/cpython/blob/main/Lib/test/test_asyncgen.py#L54
|
|
37
35
|
# before 3.10, the builtin anext() was not available
|
|
38
36
|
def py_anext(
|
|
39
|
-
iterator: AsyncIterator[T], default:
|
|
40
|
-
) -> Awaitable[
|
|
37
|
+
iterator: AsyncIterator[T], default: T | Any = _no_default
|
|
38
|
+
) -> Awaitable[T | Any | None]:
|
|
41
39
|
"""Pure-Python implementation of anext() for testing purposes.
|
|
42
40
|
|
|
43
41
|
Closely matches the builtin anext() C implementation.
|
|
@@ -52,7 +50,7 @@ def py_anext(
|
|
|
52
50
|
|
|
53
51
|
Returns:
|
|
54
52
|
The next value from the iterator, or the default value
|
|
55
|
-
|
|
53
|
+
if the iterator is exhausted.
|
|
56
54
|
|
|
57
55
|
Raises:
|
|
58
56
|
TypeError: If the iterator is not an async iterator.
|
|
@@ -68,7 +66,7 @@ def py_anext(
|
|
|
68
66
|
if default is _no_default:
|
|
69
67
|
return __anext__(iterator)
|
|
70
68
|
|
|
71
|
-
async def anext_impl() ->
|
|
69
|
+
async def anext_impl() -> T | Any:
|
|
72
70
|
try:
|
|
73
71
|
# The C code is way more low-level than this, as it implements
|
|
74
72
|
# all methods of the iterator protocol. In this implementation
|
|
@@ -90,9 +88,9 @@ class NoLock:
|
|
|
90
88
|
|
|
91
89
|
async def __aexit__(
|
|
92
90
|
self,
|
|
93
|
-
exc_type:
|
|
94
|
-
exc_val:
|
|
95
|
-
exc_tb:
|
|
91
|
+
exc_type: type[BaseException] | None,
|
|
92
|
+
exc_val: BaseException | None,
|
|
93
|
+
exc_tb: TracebackType | None,
|
|
96
94
|
) -> bool:
|
|
97
95
|
"""Return False, exception not suppressed."""
|
|
98
96
|
return False
|
|
@@ -106,10 +104,10 @@ async def tee_peer(
|
|
|
106
104
|
peers: list[deque[T]],
|
|
107
105
|
lock: AbstractAsyncContextManager[Any],
|
|
108
106
|
) -> AsyncGenerator[T, None]:
|
|
109
|
-
"""An individual iterator of a
|
|
107
|
+
"""An individual iterator of a `tee`.
|
|
110
108
|
|
|
111
109
|
This function is a generator that yields items from the shared iterator
|
|
112
|
-
|
|
110
|
+
`iterator`. It buffers items until the least advanced iterator has
|
|
113
111
|
yielded them as well. The buffer is shared with all other peers.
|
|
114
112
|
|
|
115
113
|
Args:
|
|
@@ -155,39 +153,39 @@ async def tee_peer(
|
|
|
155
153
|
|
|
156
154
|
|
|
157
155
|
class Tee(Generic[T]):
|
|
158
|
-
"""Create
|
|
156
|
+
"""Create `n` separate asynchronous iterators over `iterable`.
|
|
159
157
|
|
|
160
|
-
This splits a single
|
|
158
|
+
This splits a single `iterable` into multiple iterators, each providing
|
|
161
159
|
the same items in the same order.
|
|
162
160
|
All child iterators may advance separately but share the same items
|
|
163
|
-
from
|
|
161
|
+
from `iterable` -- when the most advanced iterator retrieves an item,
|
|
164
162
|
it is buffered until the least advanced iterator has yielded it as well.
|
|
165
|
-
A
|
|
163
|
+
A `tee` works lazily and can handle an infinite `iterable`, provided
|
|
166
164
|
that all iterators advance.
|
|
167
165
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
Unlike
|
|
176
|
-
of a :py
|
|
177
|
-
to get the child iterators. In addition, its
|
|
178
|
-
immediately closes all children, and it can be used in an
|
|
166
|
+
```python
|
|
167
|
+
async def derivative(sensor_data):
|
|
168
|
+
previous, current = a.tee(sensor_data, n=2)
|
|
169
|
+
await a.anext(previous) # advance one iterator
|
|
170
|
+
return a.map(operator.sub, previous, current)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Unlike `itertools.tee`, `.tee` returns a custom type instead
|
|
174
|
+
of a :py`tuple`. Like a tuple, it can be indexed, iterated and unpacked
|
|
175
|
+
to get the child iterators. In addition, its `.tee.aclose` method
|
|
176
|
+
immediately closes all children, and it can be used in an `async with` context
|
|
179
177
|
for the same effect.
|
|
180
178
|
|
|
181
|
-
If
|
|
182
|
-
provide these items. Also,
|
|
179
|
+
If `iterable` is an iterator and read elsewhere, `tee` will *not*
|
|
180
|
+
provide these items. Also, `tee` must internally buffer each item until the
|
|
183
181
|
last iterator has yielded it; if the most and least advanced iterator differ
|
|
184
|
-
by most data, using a :py
|
|
182
|
+
by most data, using a :py`list` is more efficient (but not lazy).
|
|
185
183
|
|
|
186
|
-
If the underlying iterable is concurrency safe (
|
|
184
|
+
If the underlying iterable is concurrency safe (`anext` may be awaited
|
|
187
185
|
concurrently) the resulting iterators are concurrency safe as well. Otherwise,
|
|
188
186
|
the iterators are safe if there is only ever one single "most advanced" iterator.
|
|
189
|
-
To enforce sequential use of
|
|
190
|
-
- e.g. an :py
|
|
187
|
+
To enforce sequential use of `anext`, provide a `lock`
|
|
188
|
+
- e.g. an :py`asyncio.Lock` instance in an :py:mod:`asyncio` application -
|
|
191
189
|
and access is automatically synchronised.
|
|
192
190
|
|
|
193
191
|
"""
|
|
@@ -197,15 +195,15 @@ class Tee(Generic[T]):
|
|
|
197
195
|
iterable: AsyncIterator[T],
|
|
198
196
|
n: int = 2,
|
|
199
197
|
*,
|
|
200
|
-
lock:
|
|
198
|
+
lock: AbstractAsyncContextManager[Any] | None = None,
|
|
201
199
|
):
|
|
202
|
-
"""Create a
|
|
200
|
+
"""Create a `tee`.
|
|
203
201
|
|
|
204
202
|
Args:
|
|
205
203
|
iterable: The iterable to split.
|
|
206
|
-
n: The number of iterators to create.
|
|
204
|
+
n: The number of iterators to create.
|
|
207
205
|
lock: The lock to synchronise access to the shared buffers.
|
|
208
|
-
|
|
206
|
+
|
|
209
207
|
"""
|
|
210
208
|
self._iterator = iterable.__aiter__() # before 3.10 aiter() doesn't exist
|
|
211
209
|
self._buffers: list[deque[T]] = [deque() for _ in range(n)]
|
|
@@ -230,8 +228,8 @@ class Tee(Generic[T]):
|
|
|
230
228
|
def __getitem__(self, item: slice) -> tuple[AsyncIterator[T], ...]: ...
|
|
231
229
|
|
|
232
230
|
def __getitem__(
|
|
233
|
-
self, item:
|
|
234
|
-
) ->
|
|
231
|
+
self, item: int | slice
|
|
232
|
+
) -> AsyncIterator[T] | tuple[AsyncIterator[T], ...]:
|
|
235
233
|
"""Return the child iterator(s) for the given index or slice."""
|
|
236
234
|
return self._children[item]
|
|
237
235
|
|
|
@@ -249,9 +247,9 @@ class Tee(Generic[T]):
|
|
|
249
247
|
|
|
250
248
|
async def __aexit__(
|
|
251
249
|
self,
|
|
252
|
-
exc_type:
|
|
253
|
-
exc_val:
|
|
254
|
-
exc_tb:
|
|
250
|
+
exc_type: type[BaseException] | None,
|
|
251
|
+
exc_val: BaseException | None,
|
|
252
|
+
exc_tb: TracebackType | None,
|
|
255
253
|
) -> bool:
|
|
256
254
|
"""Close all child iterators.
|
|
257
255
|
|
|
@@ -271,30 +269,28 @@ atee = Tee
|
|
|
271
269
|
|
|
272
270
|
|
|
273
271
|
class aclosing(AbstractAsyncContextManager): # noqa: N801
|
|
274
|
-
"""Async context manager to wrap an AsyncGenerator that has a
|
|
272
|
+
"""Async context manager to wrap an AsyncGenerator that has a `aclose()` method.
|
|
275
273
|
|
|
276
274
|
Code like this:
|
|
277
275
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
276
|
+
```python
|
|
277
|
+
async with aclosing(<module>.fetch(<arguments>)) as agen:
|
|
278
|
+
<block>
|
|
279
|
+
```
|
|
282
280
|
|
|
283
281
|
is equivalent to this:
|
|
284
282
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
await agen.aclose()
|
|
283
|
+
```python
|
|
284
|
+
agen = <module>.fetch(<arguments>)
|
|
285
|
+
try:
|
|
286
|
+
<block>
|
|
287
|
+
finally:
|
|
288
|
+
await agen.aclose()
|
|
292
289
|
|
|
290
|
+
```
|
|
293
291
|
"""
|
|
294
292
|
|
|
295
|
-
def __init__(
|
|
296
|
-
self, thing: Union[AsyncGenerator[Any, Any], AsyncIterator[Any]]
|
|
297
|
-
) -> None:
|
|
293
|
+
def __init__(self, thing: AsyncGenerator[Any, Any] | AsyncIterator[Any]) -> None:
|
|
298
294
|
"""Create the context manager.
|
|
299
295
|
|
|
300
296
|
Args:
|
|
@@ -303,15 +299,15 @@ class aclosing(AbstractAsyncContextManager): # noqa: N801
|
|
|
303
299
|
self.thing = thing
|
|
304
300
|
|
|
305
301
|
@override
|
|
306
|
-
async def __aenter__(self) ->
|
|
302
|
+
async def __aenter__(self) -> AsyncGenerator[Any, Any] | AsyncIterator[Any]:
|
|
307
303
|
return self.thing
|
|
308
304
|
|
|
309
305
|
@override
|
|
310
306
|
async def __aexit__(
|
|
311
307
|
self,
|
|
312
|
-
exc_type:
|
|
313
|
-
exc_value:
|
|
314
|
-
traceback:
|
|
308
|
+
exc_type: type[BaseException] | None,
|
|
309
|
+
exc_value: BaseException | None,
|
|
310
|
+
traceback: TracebackType | None,
|
|
315
311
|
) -> None:
|
|
316
312
|
if hasattr(self.thing, "aclose"):
|
|
317
313
|
await self.thing.aclose()
|
langchain_core/utils/env.py
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def env_var_is_set(env_var: str) -> bool:
|
|
10
10
|
"""Check if an environment variable is set.
|
|
11
11
|
|
|
12
12
|
Args:
|
|
13
|
-
env_var
|
|
13
|
+
env_var: The name of the environment variable.
|
|
14
14
|
|
|
15
15
|
Returns:
|
|
16
|
-
|
|
16
|
+
`True` if the environment variable is set, `False` otherwise.
|
|
17
17
|
"""
|
|
18
18
|
return env_var in os.environ and os.environ[env_var] not in {
|
|
19
19
|
"",
|
|
@@ -25,9 +25,9 @@ def env_var_is_set(env_var: str) -> bool:
|
|
|
25
25
|
|
|
26
26
|
def get_from_dict_or_env(
|
|
27
27
|
data: dict[str, Any],
|
|
28
|
-
key:
|
|
28
|
+
key: str | list[str],
|
|
29
29
|
env_key: str,
|
|
30
|
-
default:
|
|
30
|
+
default: str | None = None,
|
|
31
31
|
) -> str:
|
|
32
32
|
"""Get a value from a dictionary or an environment variable.
|
|
33
33
|
|
|
@@ -38,7 +38,7 @@ def get_from_dict_or_env(
|
|
|
38
38
|
env_key: The environment variable to look up if the key is not
|
|
39
39
|
in the dictionary.
|
|
40
40
|
default: The default value to return if the key is not in the dictionary
|
|
41
|
-
or the environment.
|
|
41
|
+
or the environment.
|
|
42
42
|
|
|
43
43
|
Returns:
|
|
44
44
|
The dict value or the environment variable value.
|
|
@@ -56,7 +56,7 @@ def get_from_dict_or_env(
|
|
|
56
56
|
return get_from_env(key_for_err, env_key, default=default)
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def get_from_env(key: str, env_key: str, default:
|
|
59
|
+
def get_from_env(key: str, env_key: str, default: str | None = None) -> str:
|
|
60
60
|
"""Get a value from a dictionary or an environment variable.
|
|
61
61
|
|
|
62
62
|
Args:
|
|
@@ -64,10 +64,10 @@ def get_from_env(key: str, env_key: str, default: Optional[str] = None) -> str:
|
|
|
64
64
|
env_key: The environment variable to look up if the key is not
|
|
65
65
|
in the dictionary.
|
|
66
66
|
default: The default value to return if the key is not in the dictionary
|
|
67
|
-
or the environment.
|
|
67
|
+
or the environment.
|
|
68
68
|
|
|
69
69
|
Returns:
|
|
70
|
-
|
|
70
|
+
The value of the key.
|
|
71
71
|
|
|
72
72
|
Raises:
|
|
73
73
|
ValueError: If the key is not in the dictionary and no default value is
|