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
langchain_core/stores.py
CHANGED
|
@@ -11,11 +11,11 @@ from collections.abc import AsyncIterator, Iterator, Sequence
|
|
|
11
11
|
from typing import (
|
|
12
12
|
Any,
|
|
13
13
|
Generic,
|
|
14
|
-
Optional,
|
|
15
14
|
TypeVar,
|
|
16
|
-
Union,
|
|
17
15
|
)
|
|
18
16
|
|
|
17
|
+
from typing_extensions import override
|
|
18
|
+
|
|
19
19
|
from langchain_core.exceptions import LangChainException
|
|
20
20
|
from langchain_core.runnables import run_in_executor
|
|
21
21
|
|
|
@@ -47,55 +47,53 @@ class BaseStore(ABC, Generic[K, V]):
|
|
|
47
47
|
which will usually be more efficient by saving on round trips to the store.
|
|
48
48
|
|
|
49
49
|
Examples:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
yield key
|
|
79
|
-
|
|
50
|
+
```python
|
|
51
|
+
from langchain.storage import BaseStore
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class MyInMemoryStore(BaseStore[str, int]):
|
|
55
|
+
def __init__(self) -> None:
|
|
56
|
+
self.store: dict[str, int] = {}
|
|
57
|
+
|
|
58
|
+
def mget(self, keys: Sequence[str]) -> list[int | None]:
|
|
59
|
+
return [self.store.get(key) for key in keys]
|
|
60
|
+
|
|
61
|
+
def mset(self, key_value_pairs: Sequence[tuple[str, int]]) -> None:
|
|
62
|
+
for key, value in key_value_pairs:
|
|
63
|
+
self.store[key] = value
|
|
64
|
+
|
|
65
|
+
def mdelete(self, keys: Sequence[str]) -> None:
|
|
66
|
+
for key in keys:
|
|
67
|
+
if key in self.store:
|
|
68
|
+
del self.store[key]
|
|
69
|
+
|
|
70
|
+
def yield_keys(self, prefix: str | None = None) -> Iterator[str]:
|
|
71
|
+
if prefix is None:
|
|
72
|
+
yield from self.store.keys()
|
|
73
|
+
else:
|
|
74
|
+
for key in self.store.keys():
|
|
75
|
+
if key.startswith(prefix):
|
|
76
|
+
yield key
|
|
77
|
+
```
|
|
80
78
|
"""
|
|
81
79
|
|
|
82
80
|
@abstractmethod
|
|
83
|
-
def mget(self, keys: Sequence[K]) -> list[
|
|
81
|
+
def mget(self, keys: Sequence[K]) -> list[V | None]:
|
|
84
82
|
"""Get the values associated with the given keys.
|
|
85
83
|
|
|
86
84
|
Args:
|
|
87
|
-
keys
|
|
85
|
+
keys: A sequence of keys.
|
|
88
86
|
|
|
89
87
|
Returns:
|
|
90
88
|
A sequence of optional values associated with the keys.
|
|
91
89
|
If a key is not found, the corresponding value will be None.
|
|
92
90
|
"""
|
|
93
91
|
|
|
94
|
-
async def amget(self, keys: Sequence[K]) -> list[
|
|
92
|
+
async def amget(self, keys: Sequence[K]) -> list[V | None]:
|
|
95
93
|
"""Async get the values associated with the given keys.
|
|
96
94
|
|
|
97
95
|
Args:
|
|
98
|
-
keys
|
|
96
|
+
keys: A sequence of keys.
|
|
99
97
|
|
|
100
98
|
Returns:
|
|
101
99
|
A sequence of optional values associated with the keys.
|
|
@@ -108,14 +106,14 @@ class BaseStore(ABC, Generic[K, V]):
|
|
|
108
106
|
"""Set the values for the given keys.
|
|
109
107
|
|
|
110
108
|
Args:
|
|
111
|
-
key_value_pairs
|
|
109
|
+
key_value_pairs: A sequence of key-value pairs.
|
|
112
110
|
"""
|
|
113
111
|
|
|
114
112
|
async def amset(self, key_value_pairs: Sequence[tuple[K, V]]) -> None:
|
|
115
113
|
"""Async set the values for the given keys.
|
|
116
114
|
|
|
117
115
|
Args:
|
|
118
|
-
key_value_pairs
|
|
116
|
+
key_value_pairs: A sequence of key-value pairs.
|
|
119
117
|
"""
|
|
120
118
|
return await run_in_executor(None, self.mset, key_value_pairs)
|
|
121
119
|
|
|
@@ -124,42 +122,40 @@ class BaseStore(ABC, Generic[K, V]):
|
|
|
124
122
|
"""Delete the given keys and their associated values.
|
|
125
123
|
|
|
126
124
|
Args:
|
|
127
|
-
keys
|
|
125
|
+
keys: A sequence of keys to delete.
|
|
128
126
|
"""
|
|
129
127
|
|
|
130
128
|
async def amdelete(self, keys: Sequence[K]) -> None:
|
|
131
129
|
"""Async delete the given keys and their associated values.
|
|
132
130
|
|
|
133
131
|
Args:
|
|
134
|
-
keys
|
|
132
|
+
keys: A sequence of keys to delete.
|
|
135
133
|
"""
|
|
136
134
|
return await run_in_executor(None, self.mdelete, keys)
|
|
137
135
|
|
|
138
136
|
@abstractmethod
|
|
139
|
-
def yield_keys(
|
|
140
|
-
self, *, prefix: Optional[str] = None
|
|
141
|
-
) -> Union[Iterator[K], Iterator[str]]:
|
|
137
|
+
def yield_keys(self, *, prefix: str | None = None) -> Iterator[K] | Iterator[str]:
|
|
142
138
|
"""Get an iterator over keys that match the given prefix.
|
|
143
139
|
|
|
144
140
|
Args:
|
|
145
|
-
prefix
|
|
141
|
+
prefix: The prefix to match.
|
|
146
142
|
|
|
147
143
|
Yields:
|
|
148
|
-
|
|
144
|
+
An iterator over keys that match the given prefix.
|
|
149
145
|
This method is allowed to return an iterator over either K or str
|
|
150
146
|
depending on what makes more sense for the given store.
|
|
151
147
|
"""
|
|
152
148
|
|
|
153
149
|
async def ayield_keys(
|
|
154
|
-
self, *, prefix:
|
|
155
|
-
) ->
|
|
150
|
+
self, *, prefix: str | None = None
|
|
151
|
+
) -> AsyncIterator[K] | AsyncIterator[str]:
|
|
156
152
|
"""Async get an iterator over keys that match the given prefix.
|
|
157
153
|
|
|
158
154
|
Args:
|
|
159
|
-
prefix
|
|
155
|
+
prefix: The prefix to match.
|
|
160
156
|
|
|
161
157
|
Yields:
|
|
162
|
-
|
|
158
|
+
The keys that match the given prefix.
|
|
163
159
|
This method is allowed to return an iterator over either K or str
|
|
164
160
|
depending on what makes more sense for the given store.
|
|
165
161
|
"""
|
|
@@ -182,79 +178,41 @@ class InMemoryBaseStore(BaseStore[str, V], Generic[V]):
|
|
|
182
178
|
"""Initialize an empty store."""
|
|
183
179
|
self.store: dict[str, V] = {}
|
|
184
180
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
Args:
|
|
189
|
-
keys (Sequence[str]): A sequence of keys.
|
|
190
|
-
|
|
191
|
-
Returns:
|
|
192
|
-
A sequence of optional values associated with the keys.
|
|
193
|
-
If a key is not found, the corresponding value will be None.
|
|
194
|
-
"""
|
|
181
|
+
@override
|
|
182
|
+
def mget(self, keys: Sequence[str]) -> list[V | None]:
|
|
195
183
|
return [self.store.get(key) for key in keys]
|
|
196
184
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
Args:
|
|
201
|
-
keys (Sequence[str]): A sequence of keys.
|
|
202
|
-
|
|
203
|
-
Returns:
|
|
204
|
-
A sequence of optional values associated with the keys.
|
|
205
|
-
If a key is not found, the corresponding value will be None.
|
|
206
|
-
"""
|
|
185
|
+
@override
|
|
186
|
+
async def amget(self, keys: Sequence[str]) -> list[V | None]:
|
|
207
187
|
return self.mget(keys)
|
|
208
188
|
|
|
189
|
+
@override
|
|
209
190
|
def mset(self, key_value_pairs: Sequence[tuple[str, V]]) -> None:
|
|
210
|
-
"""Set the values for the given keys.
|
|
211
|
-
|
|
212
|
-
Args:
|
|
213
|
-
key_value_pairs (Sequence[tuple[str, V]]): A sequence of key-value pairs.
|
|
214
|
-
|
|
215
|
-
Returns:
|
|
216
|
-
None
|
|
217
|
-
"""
|
|
218
191
|
for key, value in key_value_pairs:
|
|
219
192
|
self.store[key] = value
|
|
220
193
|
|
|
194
|
+
@override
|
|
221
195
|
async def amset(self, key_value_pairs: Sequence[tuple[str, V]]) -> None:
|
|
222
|
-
"""Async set the values for the given keys.
|
|
223
|
-
|
|
224
|
-
Args:
|
|
225
|
-
key_value_pairs (Sequence[tuple[str, V]]): A sequence of key-value pairs.
|
|
226
|
-
|
|
227
|
-
Returns:
|
|
228
|
-
None
|
|
229
|
-
"""
|
|
230
196
|
return self.mset(key_value_pairs)
|
|
231
197
|
|
|
198
|
+
@override
|
|
232
199
|
def mdelete(self, keys: Sequence[str]) -> None:
|
|
233
|
-
"""Delete the given keys and their associated values.
|
|
234
|
-
|
|
235
|
-
Args:
|
|
236
|
-
keys (Sequence[str]): A sequence of keys to delete.
|
|
237
|
-
"""
|
|
238
200
|
for key in keys:
|
|
239
201
|
if key in self.store:
|
|
240
202
|
del self.store[key]
|
|
241
203
|
|
|
204
|
+
@override
|
|
242
205
|
async def amdelete(self, keys: Sequence[str]) -> None:
|
|
243
|
-
"""Async delete the given keys and their associated values.
|
|
244
|
-
|
|
245
|
-
Args:
|
|
246
|
-
keys (Sequence[str]): A sequence of keys to delete.
|
|
247
|
-
"""
|
|
248
206
|
self.mdelete(keys)
|
|
249
207
|
|
|
250
|
-
def yield_keys(self, prefix:
|
|
208
|
+
def yield_keys(self, prefix: str | None = None) -> Iterator[str]:
|
|
251
209
|
"""Get an iterator over keys that match the given prefix.
|
|
252
210
|
|
|
253
211
|
Args:
|
|
254
|
-
prefix
|
|
212
|
+
prefix: The prefix to match.
|
|
255
213
|
|
|
256
214
|
Yields:
|
|
257
|
-
|
|
215
|
+
The keys that match the given prefix.
|
|
258
216
|
"""
|
|
259
217
|
if prefix is None:
|
|
260
218
|
yield from self.store.keys()
|
|
@@ -263,14 +221,14 @@ class InMemoryBaseStore(BaseStore[str, V], Generic[V]):
|
|
|
263
221
|
if key.startswith(prefix):
|
|
264
222
|
yield key
|
|
265
223
|
|
|
266
|
-
async def ayield_keys(self, prefix:
|
|
224
|
+
async def ayield_keys(self, prefix: str | None = None) -> AsyncIterator[str]:
|
|
267
225
|
"""Async get an async iterator over keys that match the given prefix.
|
|
268
226
|
|
|
269
227
|
Args:
|
|
270
|
-
prefix
|
|
228
|
+
prefix: The prefix to match.
|
|
271
229
|
|
|
272
230
|
Yields:
|
|
273
|
-
|
|
231
|
+
The keys that match the given prefix.
|
|
274
232
|
"""
|
|
275
233
|
if prefix is None:
|
|
276
234
|
for key in self.store:
|
|
@@ -289,21 +247,19 @@ class InMemoryStore(InMemoryBaseStore[Any]):
|
|
|
289
247
|
the key-value pairs.
|
|
290
248
|
|
|
291
249
|
Examples:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
# ['key2']
|
|
306
|
-
|
|
250
|
+
```python
|
|
251
|
+
from langchain.storage import InMemoryStore
|
|
252
|
+
|
|
253
|
+
store = InMemoryStore()
|
|
254
|
+
store.mset([("key1", "value1"), ("key2", "value2")])
|
|
255
|
+
store.mget(["key1", "key2"])
|
|
256
|
+
# ['value1', 'value2']
|
|
257
|
+
store.mdelete(["key1"])
|
|
258
|
+
list(store.yield_keys())
|
|
259
|
+
# ['key2']
|
|
260
|
+
list(store.yield_keys(prefix="k"))
|
|
261
|
+
# ['key2']
|
|
262
|
+
```
|
|
307
263
|
"""
|
|
308
264
|
|
|
309
265
|
|
|
@@ -315,21 +271,19 @@ class InMemoryByteStore(InMemoryBaseStore[bytes]):
|
|
|
315
271
|
the key-value pairs.
|
|
316
272
|
|
|
317
273
|
Examples:
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
# ['key2']
|
|
332
|
-
|
|
274
|
+
```python
|
|
275
|
+
from langchain.storage import InMemoryByteStore
|
|
276
|
+
|
|
277
|
+
store = InMemoryByteStore()
|
|
278
|
+
store.mset([("key1", b"value1"), ("key2", b"value2")])
|
|
279
|
+
store.mget(["key1", "key2"])
|
|
280
|
+
# [b'value1', b'value2']
|
|
281
|
+
store.mdelete(["key1"])
|
|
282
|
+
list(store.yield_keys())
|
|
283
|
+
# ['key2']
|
|
284
|
+
list(store.yield_keys(prefix="k"))
|
|
285
|
+
# ['key2']
|
|
286
|
+
```
|
|
333
287
|
"""
|
|
334
288
|
|
|
335
289
|
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from abc import ABC, abstractmethod
|
|
6
6
|
from enum import Enum
|
|
7
|
-
from typing import TYPE_CHECKING, Any
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
8
|
|
|
9
9
|
from pydantic import BaseModel
|
|
10
10
|
|
|
@@ -15,12 +15,12 @@ if TYPE_CHECKING:
|
|
|
15
15
|
class Visitor(ABC):
|
|
16
16
|
"""Defines interface for IR translation using a visitor pattern."""
|
|
17
17
|
|
|
18
|
-
allowed_comparators:
|
|
18
|
+
allowed_comparators: Sequence[Comparator] | None = None
|
|
19
19
|
"""Allowed comparators for the visitor."""
|
|
20
|
-
allowed_operators:
|
|
20
|
+
allowed_operators: Sequence[Operator] | None = None
|
|
21
21
|
"""Allowed operators for the visitor."""
|
|
22
22
|
|
|
23
|
-
def _validate_func(self, func:
|
|
23
|
+
def _validate_func(self, func: Operator | Comparator) -> None:
|
|
24
24
|
if (
|
|
25
25
|
isinstance(func, Operator)
|
|
26
26
|
and self.allowed_operators is not None
|
|
@@ -143,7 +143,7 @@ class Comparison(FilterDirective):
|
|
|
143
143
|
value: The value to compare to.
|
|
144
144
|
"""
|
|
145
145
|
# super exists from BaseModel
|
|
146
|
-
super().__init__(
|
|
146
|
+
super().__init__(
|
|
147
147
|
comparator=comparator, attribute=attribute, value=value, **kwargs
|
|
148
148
|
)
|
|
149
149
|
|
|
@@ -166,9 +166,7 @@ class Operation(FilterDirective):
|
|
|
166
166
|
arguments: The arguments to the operator.
|
|
167
167
|
"""
|
|
168
168
|
# super exists from BaseModel
|
|
169
|
-
super().__init__(
|
|
170
|
-
operator=operator, arguments=arguments, **kwargs
|
|
171
|
-
)
|
|
169
|
+
super().__init__(operator=operator, arguments=arguments, **kwargs)
|
|
172
170
|
|
|
173
171
|
|
|
174
172
|
class StructuredQuery(Expr):
|
|
@@ -176,16 +174,16 @@ class StructuredQuery(Expr):
|
|
|
176
174
|
|
|
177
175
|
query: str
|
|
178
176
|
"""Query string."""
|
|
179
|
-
filter:
|
|
177
|
+
filter: FilterDirective | None
|
|
180
178
|
"""Filtering expression."""
|
|
181
|
-
limit:
|
|
179
|
+
limit: int | None
|
|
182
180
|
"""Limit on the number of results."""
|
|
183
181
|
|
|
184
182
|
def __init__(
|
|
185
183
|
self,
|
|
186
184
|
query: str,
|
|
187
|
-
filter:
|
|
188
|
-
limit:
|
|
185
|
+
filter: FilterDirective | None, # noqa: A002
|
|
186
|
+
limit: int | None = None,
|
|
189
187
|
**kwargs: Any,
|
|
190
188
|
) -> None:
|
|
191
189
|
"""Create a StructuredQuery.
|
|
@@ -196,6 +194,4 @@ class StructuredQuery(Expr):
|
|
|
196
194
|
limit: The limit on the number of results.
|
|
197
195
|
"""
|
|
198
196
|
# super exists from BaseModel
|
|
199
|
-
super().__init__(
|
|
200
|
-
query=query, filter=filter, limit=limit, **kwargs
|
|
201
|
-
)
|
|
197
|
+
super().__init__(query=query, filter=filter, limit=limit, **kwargs)
|
langchain_core/sys_info.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Print information about the system and langchain packages for debugging purposes."""
|
|
2
2
|
|
|
3
|
+
import pkgutil
|
|
4
|
+
import platform
|
|
5
|
+
import re
|
|
6
|
+
import sys
|
|
3
7
|
from collections.abc import Sequence
|
|
8
|
+
from importlib import metadata, util
|
|
4
9
|
|
|
5
10
|
|
|
6
11
|
def _get_sub_deps(packages: Sequence[str]) -> list[str]:
|
|
7
12
|
"""Get any specified sub-dependencies."""
|
|
8
|
-
from importlib import metadata
|
|
9
|
-
|
|
10
13
|
sub_deps = set()
|
|
11
14
|
underscored_packages = {pkg.replace("-", "_") for pkg in packages}
|
|
12
15
|
|
|
@@ -20,9 +23,12 @@ def _get_sub_deps(packages: Sequence[str]) -> list[str]:
|
|
|
20
23
|
continue
|
|
21
24
|
|
|
22
25
|
for req in required:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
# Extract package name (e.g., "httpx<1,>=0.23.0" -> "httpx")
|
|
27
|
+
match = re.match(r"^([a-zA-Z0-9_.-]+)", req)
|
|
28
|
+
if match:
|
|
29
|
+
pkg_name = match.group(1)
|
|
30
|
+
if pkg_name.replace("-", "_") not in underscored_packages:
|
|
31
|
+
sub_deps.add(pkg_name)
|
|
26
32
|
|
|
27
33
|
return sorted(sub_deps, key=lambda x: x.lower())
|
|
28
34
|
|
|
@@ -33,11 +39,6 @@ def print_sys_info(*, additional_pkgs: Sequence[str] = ()) -> None:
|
|
|
33
39
|
Args:
|
|
34
40
|
additional_pkgs: Additional packages to include in the output.
|
|
35
41
|
"""
|
|
36
|
-
import pkgutil
|
|
37
|
-
import platform
|
|
38
|
-
import sys
|
|
39
|
-
from importlib import metadata, util
|
|
40
|
-
|
|
41
42
|
# Packages that do not start with "langchain" prefix.
|
|
42
43
|
other_langchain_packages = [
|
|
43
44
|
"langserve",
|
|
@@ -74,17 +75,17 @@ def print_sys_info(*, additional_pkgs: Sequence[str] = ()) -> None:
|
|
|
74
75
|
"OS Version": platform.version(),
|
|
75
76
|
"Python Version": sys.version,
|
|
76
77
|
}
|
|
77
|
-
print()
|
|
78
|
-
print("System Information")
|
|
79
|
-
print("------------------")
|
|
80
|
-
print("> OS: ", system_info["OS"])
|
|
81
|
-
print("> OS Version: ", system_info["OS Version"])
|
|
82
|
-
print("> Python Version: ", system_info["Python Version"])
|
|
78
|
+
print()
|
|
79
|
+
print("System Information")
|
|
80
|
+
print("------------------")
|
|
81
|
+
print("> OS: ", system_info["OS"])
|
|
82
|
+
print("> OS Version: ", system_info["OS Version"])
|
|
83
|
+
print("> Python Version: ", system_info["Python Version"])
|
|
83
84
|
|
|
84
85
|
# Print out only langchain packages
|
|
85
|
-
print()
|
|
86
|
-
print("Package Information")
|
|
87
|
-
print("-------------------")
|
|
86
|
+
print()
|
|
87
|
+
print("Package Information")
|
|
88
|
+
print("-------------------")
|
|
88
89
|
|
|
89
90
|
not_installed = []
|
|
90
91
|
|
|
@@ -105,30 +106,28 @@ def print_sys_info(*, additional_pkgs: Sequence[str] = ()) -> None:
|
|
|
105
106
|
|
|
106
107
|
# Print package with version
|
|
107
108
|
if package_version is not None:
|
|
108
|
-
print(f"> {pkg}: {package_version}")
|
|
109
|
-
else:
|
|
110
|
-
print(f"> {pkg}: Installed. No version info available.") # noqa: T201
|
|
109
|
+
print(f"> {pkg}: {package_version}")
|
|
111
110
|
|
|
112
111
|
if not_installed:
|
|
113
|
-
print()
|
|
114
|
-
print("Optional packages not installed")
|
|
115
|
-
print("-------------------------------")
|
|
112
|
+
print()
|
|
113
|
+
print("Optional packages not installed")
|
|
114
|
+
print("-------------------------------")
|
|
116
115
|
for pkg in not_installed:
|
|
117
|
-
print(f"> {pkg}")
|
|
116
|
+
print(f"> {pkg}")
|
|
118
117
|
|
|
119
118
|
sub_dependencies = _get_sub_deps(all_packages)
|
|
120
119
|
|
|
121
120
|
if sub_dependencies:
|
|
122
|
-
print()
|
|
123
|
-
print("Other Dependencies")
|
|
124
|
-
print("------------------")
|
|
121
|
+
print()
|
|
122
|
+
print("Other Dependencies")
|
|
123
|
+
print("------------------")
|
|
125
124
|
|
|
126
125
|
for dep in sub_dependencies:
|
|
127
126
|
try:
|
|
128
127
|
dep_version = metadata.version(dep)
|
|
129
|
-
print(f"> {dep}: {dep_version}")
|
|
128
|
+
print(f"> {dep}: {dep_version}")
|
|
130
129
|
except Exception:
|
|
131
|
-
print(f"> {dep}: Installed. No version info available.")
|
|
130
|
+
print(f"> {dep}: Installed. No version info available.")
|
|
132
131
|
|
|
133
132
|
|
|
134
133
|
if __name__ == "__main__":
|
langchain_core/tools/__init__.py
CHANGED
|
@@ -2,20 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Each tool has a **description**. Agent uses the description to choose the right
|
|
4
4
|
tool for the job.
|
|
5
|
-
|
|
6
|
-
**Class hierarchy:**
|
|
7
|
-
|
|
8
|
-
.. code-block::
|
|
9
|
-
|
|
10
|
-
RunnableSerializable --> BaseTool --> <name>Tool # Examples: AIPluginTool, BaseGraphQLTool
|
|
11
|
-
<name> # Examples: BraveSearch, HumanInputRun
|
|
12
|
-
|
|
13
|
-
**Main helpers:**
|
|
14
|
-
|
|
15
|
-
.. code-block::
|
|
16
|
-
|
|
17
|
-
CallbackManagerForToolRun, AsyncCallbackManagerForToolRun
|
|
18
|
-
""" # noqa: E501
|
|
5
|
+
"""
|
|
19
6
|
|
|
20
7
|
from __future__ import annotations
|
|
21
8
|
|