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
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
- .. code-block:: python
52
-
53
- from langchain.storage import BaseStore
54
-
55
- class MyInMemoryStore(BaseStore[str, int]):
56
-
57
- def __init__(self):
58
- self.store = {}
59
-
60
- def mget(self, keys):
61
- return [self.store.get(key) for key in keys]
62
-
63
- def mset(self, key_value_pairs):
64
- for key, value in key_value_pairs:
65
- self.store[key] = value
66
-
67
- def mdelete(self, keys):
68
- for key in keys:
69
- if key in self.store:
70
- del self.store[key]
71
-
72
- def yield_keys(self, prefix=None):
73
- if prefix is None:
74
- yield from self.store.keys()
75
- else:
76
- for key in self.store.keys():
77
- if key.startswith(prefix):
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[Optional[V]]:
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 (Sequence[K]): A sequence of 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[Optional[V]]:
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 (Sequence[K]): A sequence of 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 (Sequence[tuple[K, V]]): A sequence of 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 (Sequence[tuple[K, V]]): A sequence of 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 (Sequence[K]): A sequence of keys to delete.
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 (Sequence[K]): A sequence of keys to delete.
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 (str): The prefix to match.
141
+ prefix: The prefix to match.
146
142
 
147
143
  Yields:
148
- Iterator[K | str]: An iterator over keys that match the given prefix.
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: Optional[str] = None
155
- ) -> Union[AsyncIterator[K], AsyncIterator[str]]:
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 (str): The prefix to match.
155
+ prefix: The prefix to match.
160
156
 
161
157
  Yields:
162
- Iterator[K | str]: An iterator over keys that match the given prefix.
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
- def mget(self, keys: Sequence[str]) -> list[Optional[V]]:
186
- """Get the values associated with the given keys.
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
- async def amget(self, keys: Sequence[str]) -> list[Optional[V]]:
198
- """Async get the values associated with the given keys.
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: Optional[str] = None) -> Iterator[str]:
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 (str, optional): The prefix to match. Defaults to None.
212
+ prefix: The prefix to match.
255
213
 
256
214
  Yields:
257
- Iterator[str]: An iterator over keys that match the given prefix.
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: Optional[str] = None) -> AsyncIterator[str]:
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 (str, optional): The prefix to match. Defaults to None.
228
+ prefix: The prefix to match.
271
229
 
272
230
  Yields:
273
- AsyncIterator[str]: An async iterator over keys that match the given prefix.
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
- .. code-block:: python
294
-
295
- from langchain.storage import InMemoryStore
296
-
297
- store = InMemoryStore()
298
- store.mset([('key1', 'value1'), ('key2', 'value2')])
299
- store.mget(['key1', 'key2'])
300
- # ['value1', 'value2']
301
- store.mdelete(['key1'])
302
- list(store.yield_keys())
303
- # ['key2']
304
- list(store.yield_keys(prefix='k'))
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
- .. code-block:: python
320
-
321
- from langchain.storage import InMemoryByteStore
322
-
323
- store = InMemoryByteStore()
324
- store.mset([('key1', b'value1'), ('key2', b'value2')])
325
- store.mget(['key1', 'key2'])
326
- # [b'value1', b'value2']
327
- store.mdelete(['key1'])
328
- list(store.yield_keys())
329
- # ['key2']
330
- list(store.yield_keys(prefix='k'))
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, Optional, Union
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: Optional[Sequence[Comparator]] = None
18
+ allowed_comparators: Sequence[Comparator] | None = None
19
19
  """Allowed comparators for the visitor."""
20
- allowed_operators: Optional[Sequence[Operator]] = None
20
+ allowed_operators: Sequence[Operator] | None = None
21
21
  """Allowed operators for the visitor."""
22
22
 
23
- def _validate_func(self, func: Union[Operator, Comparator]) -> None:
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__( # type: ignore[call-arg]
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__( # type: ignore[call-arg]
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: Optional[FilterDirective]
177
+ filter: FilterDirective | None
180
178
  """Filtering expression."""
181
- limit: Optional[int]
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: Optional[FilterDirective], # noqa: A002
188
- limit: Optional[int] = None,
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__( # type: ignore[call-arg]
200
- query=query, filter=filter, limit=limit, **kwargs
201
- )
197
+ super().__init__(query=query, filter=filter, limit=limit, **kwargs)
@@ -1,12 +1,15 @@
1
- """**sys_info** prints information about the system and langchain packages for debugging purposes.""" # noqa: E501
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
- cleaned_req = req.split(" ")[0]
24
- if cleaned_req.replace("-", "_") not in underscored_packages:
25
- sub_deps.add(cleaned_req)
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() # noqa: T201
78
- print("System Information") # noqa: T201
79
- print("------------------") # noqa: T201
80
- print("> OS: ", system_info["OS"]) # noqa: T201
81
- print("> OS Version: ", system_info["OS Version"]) # noqa: T201
82
- print("> Python Version: ", system_info["Python Version"]) # noqa: T201
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() # noqa: T201
86
- print("Package Information") # noqa: T201
87
- print("-------------------") # noqa: T201
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}") # noqa: T201
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() # noqa: T201
114
- print("Optional packages not installed") # noqa: T201
115
- print("-------------------------------") # noqa: T201
112
+ print()
113
+ print("Optional packages not installed")
114
+ print("-------------------------------")
116
115
  for pkg in not_installed:
117
- print(f"> {pkg}") # noqa: T201
116
+ print(f"> {pkg}")
118
117
 
119
118
  sub_dependencies = _get_sub_deps(all_packages)
120
119
 
121
120
  if sub_dependencies:
122
- print() # noqa: T201
123
- print("Other Dependencies") # noqa: T201
124
- print("------------------") # noqa: T201
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}") # noqa: T201
128
+ print(f"> {dep}: {dep_version}")
130
129
  except Exception:
131
- print(f"> {dep}: Installed. No version info available.") # noqa: T201
130
+ print(f"> {dep}: Installed. No version info available.")
132
131
 
133
132
 
134
133
  if __name__ == "__main__":
@@ -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