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/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""`langchain-core` defines the base abstractions for the LangChain ecosystem.
|
|
2
2
|
|
|
3
3
|
The interfaces for core components like chat models, LLMs, vector stores, retrievers,
|
|
4
4
|
and more are defined here. The universal invocation protocol (Runnables) along with
|
langchain_core/_api/__init__.py
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This module is only relevant for LangChain developers, not for users.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
This module and its submodules are for internal use only. Do not use them
|
|
8
|
-
in your own code. We may change the API at any time with no warning.
|
|
5
|
+
!!! warning
|
|
9
6
|
|
|
7
|
+
This module and its submodules are for internal use only. Do not use them in your
|
|
8
|
+
own code. We may change the API at any time with no warning.
|
|
10
9
|
"""
|
|
11
10
|
|
|
12
11
|
from typing import TYPE_CHECKING
|
|
@@ -4,18 +4,18 @@ This module was loosely adapted from matplotlibs _api/deprecation.py module:
|
|
|
4
4
|
|
|
5
5
|
https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
!!! warning
|
|
8
8
|
|
|
9
|
-
This module is for internal use only.
|
|
10
|
-
|
|
9
|
+
This module is for internal use only. Do not use it in your own code. We may change
|
|
10
|
+
the API at any time with no warning.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
import contextlib
|
|
14
14
|
import functools
|
|
15
15
|
import inspect
|
|
16
16
|
import warnings
|
|
17
|
-
from collections.abc import Generator
|
|
18
|
-
from typing import Any,
|
|
17
|
+
from collections.abc import Callable, Generator
|
|
18
|
+
from typing import Any, TypeVar, cast
|
|
19
19
|
|
|
20
20
|
from langchain_core._api.internal import is_caller_internal
|
|
21
21
|
|
|
@@ -27,7 +27,7 @@ class LangChainBetaWarning(DeprecationWarning):
|
|
|
27
27
|
# PUBLIC API
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
T = TypeVar("T", bound=
|
|
30
|
+
T = TypeVar("T", bound=Callable[..., Any] | type)
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def beta(
|
|
@@ -40,37 +40,37 @@ def beta(
|
|
|
40
40
|
"""Decorator to mark a function, a class, or a property as beta.
|
|
41
41
|
|
|
42
42
|
When marking a classmethod, a staticmethod, or a property, the
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
underlying callable), but *over*
|
|
43
|
+
`@beta` decorator should go *under* `@classmethod` and
|
|
44
|
+
`@staticmethod` (i.e., `beta` should directly decorate the
|
|
45
|
+
underlying callable), but *over* `@property`.
|
|
46
46
|
|
|
47
|
-
When marking a class
|
|
48
|
-
multiple inheritance hierarchy,
|
|
49
|
-
(if
|
|
50
|
-
|
|
51
|
-
own (annotation-emitting)
|
|
47
|
+
When marking a class `C` intended to be used as a base class in a
|
|
48
|
+
multiple inheritance hierarchy, `C` *must* define an `__init__` method
|
|
49
|
+
(if `C` instead inherited its `__init__` from its own base class, then
|
|
50
|
+
`@beta` would mess up `__init__` inheritance when installing its
|
|
51
|
+
own (annotation-emitting) `C.__init__`).
|
|
52
52
|
|
|
53
53
|
Args:
|
|
54
|
-
message
|
|
54
|
+
message:
|
|
55
55
|
Override the default beta message. The %(since)s,
|
|
56
56
|
%(name)s, %(alternative)s, %(obj_type)s, %(addendum)s,
|
|
57
57
|
and %(removal)s format specifiers will be replaced by the
|
|
58
58
|
values of the respective arguments passed to this function.
|
|
59
|
-
name
|
|
59
|
+
name:
|
|
60
60
|
The name of the beta object.
|
|
61
|
-
obj_type
|
|
61
|
+
obj_type:
|
|
62
62
|
The object type being beta.
|
|
63
|
-
addendum
|
|
63
|
+
addendum:
|
|
64
64
|
Additional text appended directly to the final message.
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.. code-block:: python
|
|
69
|
-
|
|
70
|
-
@beta
|
|
71
|
-
def the_function_to_annotate():
|
|
72
|
-
pass
|
|
66
|
+
Returns:
|
|
67
|
+
A decorator which can be used to mark functions or classes as beta.
|
|
73
68
|
|
|
69
|
+
```python
|
|
70
|
+
@beta
|
|
71
|
+
def the_function_to_annotate():
|
|
72
|
+
pass
|
|
73
|
+
```
|
|
74
74
|
"""
|
|
75
75
|
|
|
76
76
|
def beta(
|
|
@@ -144,58 +144,33 @@ def beta(
|
|
|
144
144
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
|
145
145
|
warn_if_direct_instance
|
|
146
146
|
)
|
|
147
|
-
return
|
|
147
|
+
return obj
|
|
148
148
|
|
|
149
149
|
elif isinstance(obj, property):
|
|
150
|
-
# note(erick): this block doesn't seem to be used?
|
|
151
150
|
if not _obj_type:
|
|
152
151
|
_obj_type = "attribute"
|
|
153
152
|
wrapped = None
|
|
154
153
|
_name = _name or obj.fget.__qualname__
|
|
155
154
|
old_doc = obj.__doc__
|
|
156
155
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
self,
|
|
162
|
-
fget: Union[Callable[[Any], Any], None] = None,
|
|
163
|
-
fset: Union[Callable[[Any, Any], None], None] = None,
|
|
164
|
-
fdel: Union[Callable[[Any], None], None] = None,
|
|
165
|
-
doc: Union[str, None] = None,
|
|
166
|
-
) -> None:
|
|
167
|
-
super().__init__(fget, fset, fdel, doc)
|
|
168
|
-
self.__orig_fget = fget
|
|
169
|
-
self.__orig_fset = fset
|
|
170
|
-
self.__orig_fdel = fdel
|
|
171
|
-
|
|
172
|
-
def __get__(
|
|
173
|
-
self, instance: Any, owner: Union[type, None] = None
|
|
174
|
-
) -> Any:
|
|
175
|
-
if instance is not None or owner is not None:
|
|
176
|
-
emit_warning()
|
|
177
|
-
return self.fget(instance)
|
|
156
|
+
def _fget(instance: Any) -> Any:
|
|
157
|
+
if instance is not None:
|
|
158
|
+
emit_warning()
|
|
159
|
+
return obj.fget(instance)
|
|
178
160
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
161
|
+
def _fset(instance: Any, value: Any) -> None:
|
|
162
|
+
if instance is not None:
|
|
163
|
+
emit_warning()
|
|
164
|
+
obj.fset(instance, value)
|
|
183
165
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def __set_name__(self, owner: Union[type, None], set_name: str) -> None:
|
|
190
|
-
nonlocal _name
|
|
191
|
-
if _name == "<lambda>":
|
|
192
|
-
_name = set_name
|
|
166
|
+
def _fdel(instance: Any) -> None:
|
|
167
|
+
if instance is not None:
|
|
168
|
+
emit_warning()
|
|
169
|
+
obj.fdel(instance)
|
|
193
170
|
|
|
194
|
-
def finalize(
|
|
171
|
+
def finalize(_wrapper: Callable[..., Any], new_doc: str) -> Any:
|
|
195
172
|
"""Finalize the property."""
|
|
196
|
-
return
|
|
197
|
-
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
|
198
|
-
)
|
|
173
|
+
return property(fget=_fget, fset=_fset, fdel=_fdel, doc=new_doc)
|
|
199
174
|
|
|
200
175
|
else:
|
|
201
176
|
_name = _name or obj.__qualname__
|
|
@@ -249,17 +224,17 @@ def warn_beta(
|
|
|
249
224
|
) -> None:
|
|
250
225
|
"""Display a standardized beta annotation.
|
|
251
226
|
|
|
252
|
-
|
|
253
|
-
message
|
|
227
|
+
Args:
|
|
228
|
+
message:
|
|
254
229
|
Override the default beta message. The
|
|
255
230
|
%(name)s, %(obj_type)s, %(addendum)s
|
|
256
231
|
format specifiers will be replaced by the
|
|
257
232
|
values of the respective arguments passed to this function.
|
|
258
|
-
name
|
|
233
|
+
name:
|
|
259
234
|
The name of the annotated object.
|
|
260
|
-
obj_type
|
|
235
|
+
obj_type:
|
|
261
236
|
The object type being annotated.
|
|
262
|
-
addendum
|
|
237
|
+
addendum:
|
|
263
238
|
Additional text appended directly to the final message.
|
|
264
239
|
"""
|
|
265
240
|
if not message:
|
|
@@ -4,28 +4,26 @@ This module was adapted from matplotlibs _api/deprecation.py module:
|
|
|
4
4
|
|
|
5
5
|
https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
!!! warning
|
|
8
8
|
|
|
9
|
-
This module is for internal use only.
|
|
10
|
-
|
|
9
|
+
This module is for internal use only. Do not use it in your own code. We may change
|
|
10
|
+
the API at any time with no warning.
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
import contextlib
|
|
14
14
|
import functools
|
|
15
15
|
import inspect
|
|
16
16
|
import warnings
|
|
17
|
-
from collections.abc import Generator
|
|
17
|
+
from collections.abc import Callable, Generator
|
|
18
18
|
from typing import (
|
|
19
19
|
Any,
|
|
20
|
-
|
|
20
|
+
ParamSpec,
|
|
21
21
|
TypeVar,
|
|
22
|
-
Union,
|
|
23
22
|
cast,
|
|
24
23
|
)
|
|
25
24
|
|
|
26
25
|
from pydantic.fields import FieldInfo
|
|
27
26
|
from pydantic.v1.fields import FieldInfo as FieldInfoV1
|
|
28
|
-
from typing_extensions import ParamSpec
|
|
29
27
|
|
|
30
28
|
from langchain_core._api.internal import is_caller_internal
|
|
31
29
|
|
|
@@ -42,7 +40,7 @@ class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
|
|
|
42
40
|
|
|
43
41
|
|
|
44
42
|
# Last Any should be FieldInfoV1 but this leads to circular imports
|
|
45
|
-
T = TypeVar("T", bound=
|
|
43
|
+
T = TypeVar("T", bound=type | Callable[..., Any] | Any)
|
|
46
44
|
|
|
47
45
|
|
|
48
46
|
def _validate_deprecation_params(
|
|
@@ -84,59 +82,59 @@ def deprecated(
|
|
|
84
82
|
"""Decorator to mark a function, a class, or a property as deprecated.
|
|
85
83
|
|
|
86
84
|
When deprecating a classmethod, a staticmethod, or a property, the
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
underlying callable), but *over*
|
|
85
|
+
`@deprecated` decorator should go *under* `@classmethod` and
|
|
86
|
+
`@staticmethod` (i.e., `deprecated` should directly decorate the
|
|
87
|
+
underlying callable), but *over* `@property`.
|
|
90
88
|
|
|
91
|
-
When deprecating a class
|
|
92
|
-
multiple inheritance hierarchy,
|
|
93
|
-
(if
|
|
94
|
-
|
|
95
|
-
own (deprecation-emitting)
|
|
89
|
+
When deprecating a class `C` intended to be used as a base class in a
|
|
90
|
+
multiple inheritance hierarchy, `C` *must* define an `__init__` method
|
|
91
|
+
(if `C` instead inherited its `__init__` from its own base class, then
|
|
92
|
+
`@deprecated` would mess up `__init__` inheritance when installing its
|
|
93
|
+
own (deprecation-emitting) `C.__init__`).
|
|
96
94
|
|
|
97
95
|
Parameters are the same as for `warn_deprecated`, except that *obj_type*
|
|
98
96
|
defaults to 'class' if decorating a class, 'attribute' if decorating a
|
|
99
97
|
property, and 'function' otherwise.
|
|
100
98
|
|
|
101
99
|
Args:
|
|
102
|
-
since
|
|
100
|
+
since:
|
|
103
101
|
The release at which this API became deprecated.
|
|
104
|
-
message
|
|
102
|
+
message:
|
|
105
103
|
Override the default deprecation message. The %(since)s,
|
|
106
104
|
%(name)s, %(alternative)s, %(obj_type)s, %(addendum)s,
|
|
107
105
|
and %(removal)s format specifiers will be replaced by the
|
|
108
106
|
values of the respective arguments passed to this function.
|
|
109
|
-
name
|
|
107
|
+
name:
|
|
110
108
|
The name of the deprecated object.
|
|
111
|
-
alternative
|
|
109
|
+
alternative:
|
|
112
110
|
An alternative API that the user may use in place of the
|
|
113
111
|
deprecated API. The deprecation warning will tell the user
|
|
114
112
|
about this alternative if provided.
|
|
115
|
-
alternative_import:
|
|
113
|
+
alternative_import:
|
|
116
114
|
An alternative import that the user may use instead.
|
|
117
|
-
pending
|
|
118
|
-
If True
|
|
115
|
+
pending:
|
|
116
|
+
If `True`, uses a `PendingDeprecationWarning` instead of a
|
|
119
117
|
DeprecationWarning. Cannot be used together with removal.
|
|
120
|
-
obj_type
|
|
118
|
+
obj_type:
|
|
121
119
|
The object type being deprecated.
|
|
122
|
-
addendum
|
|
120
|
+
addendum:
|
|
123
121
|
Additional text appended directly to the final message.
|
|
124
|
-
removal
|
|
122
|
+
removal:
|
|
125
123
|
The expected removal version. With the default (an empty
|
|
126
124
|
string), a removal version is automatically computed from
|
|
127
125
|
since. Set to other Falsy values to not schedule a removal
|
|
128
126
|
date. Cannot be used together with pending.
|
|
129
|
-
package:
|
|
127
|
+
package:
|
|
130
128
|
The package of the deprecated object.
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
.. code-block:: python
|
|
135
|
-
|
|
136
|
-
@deprecated('1.4.0')
|
|
137
|
-
def the_function_to_deprecate():
|
|
138
|
-
pass
|
|
130
|
+
Returns:
|
|
131
|
+
A decorator to mark a function or class as deprecated.
|
|
139
132
|
|
|
133
|
+
```python
|
|
134
|
+
@deprecated("1.4.0")
|
|
135
|
+
def the_function_to_deprecate():
|
|
136
|
+
pass
|
|
137
|
+
```
|
|
140
138
|
"""
|
|
141
139
|
_validate_deprecation_params(
|
|
142
140
|
removal, alternative, alternative_import, pending=pending
|
|
@@ -225,7 +223,7 @@ def deprecated(
|
|
|
225
223
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
|
226
224
|
warn_if_direct_instance
|
|
227
225
|
)
|
|
228
|
-
return
|
|
226
|
+
return obj
|
|
229
227
|
|
|
230
228
|
elif isinstance(obj, FieldInfoV1):
|
|
231
229
|
wrapped = None
|
|
@@ -273,7 +271,7 @@ def deprecated(
|
|
|
273
271
|
if not _obj_type:
|
|
274
272
|
_obj_type = "attribute"
|
|
275
273
|
wrapped = None
|
|
276
|
-
_name = _name or cast("
|
|
274
|
+
_name = _name or cast("type | Callable", obj.fget).__qualname__
|
|
277
275
|
old_doc = obj.__doc__
|
|
278
276
|
|
|
279
277
|
class _DeprecatedProperty(property):
|
|
@@ -281,19 +279,17 @@ def deprecated(
|
|
|
281
279
|
|
|
282
280
|
def __init__(
|
|
283
281
|
self,
|
|
284
|
-
fget:
|
|
285
|
-
fset:
|
|
286
|
-
fdel:
|
|
287
|
-
doc:
|
|
282
|
+
fget: Callable[[Any], Any] | None = None,
|
|
283
|
+
fset: Callable[[Any, Any], None] | None = None,
|
|
284
|
+
fdel: Callable[[Any], None] | None = None,
|
|
285
|
+
doc: str | None = None,
|
|
288
286
|
) -> None:
|
|
289
287
|
super().__init__(fget, fset, fdel, doc)
|
|
290
288
|
self.__orig_fget = fget
|
|
291
289
|
self.__orig_fset = fset
|
|
292
290
|
self.__orig_fdel = fdel
|
|
293
291
|
|
|
294
|
-
def __get__(
|
|
295
|
-
self, instance: Any, owner: Union[type, None] = None
|
|
296
|
-
) -> Any:
|
|
292
|
+
def __get__(self, instance: Any, owner: type | None = None) -> Any:
|
|
297
293
|
if instance is not None or owner is not None:
|
|
298
294
|
emit_warning()
|
|
299
295
|
if self.fget is None:
|
|
@@ -312,7 +308,7 @@ def deprecated(
|
|
|
312
308
|
if self.fdel is not None:
|
|
313
309
|
self.fdel(instance)
|
|
314
310
|
|
|
315
|
-
def __set_name__(self, owner:
|
|
311
|
+
def __set_name__(self, owner: type | None, set_name: str) -> None:
|
|
316
312
|
nonlocal _name
|
|
317
313
|
if _name == "<lambda>":
|
|
318
314
|
_name = set_name
|
|
@@ -327,7 +323,7 @@ def deprecated(
|
|
|
327
323
|
)
|
|
328
324
|
|
|
329
325
|
else:
|
|
330
|
-
_name = _name or cast("
|
|
326
|
+
_name = _name or cast("type | Callable", obj).__qualname__
|
|
331
327
|
if not _obj_type:
|
|
332
328
|
# edge case: when a function is within another function
|
|
333
329
|
# within a test, this will call it a "method" not a "function"
|
|
@@ -358,25 +354,22 @@ def deprecated(
|
|
|
358
354
|
# Modify the docstring to include a deprecation notice.
|
|
359
355
|
if (
|
|
360
356
|
_alternative
|
|
361
|
-
and _alternative.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
_alternative = f":class:`~{_alternative}`"
|
|
357
|
+
and _alternative.rsplit(".", maxsplit=1)[-1].lower()
|
|
358
|
+
== _alternative.rsplit(".", maxsplit=1)[-1]
|
|
359
|
+
) or _alternative:
|
|
360
|
+
_alternative = f"`{_alternative}`"
|
|
366
361
|
|
|
367
362
|
if (
|
|
368
363
|
_alternative_import
|
|
369
|
-
and _alternative_import.
|
|
370
|
-
== _alternative_import.
|
|
371
|
-
):
|
|
372
|
-
_alternative_import = f"
|
|
373
|
-
elif _alternative_import:
|
|
374
|
-
_alternative_import = f":class:`~{_alternative_import}`"
|
|
364
|
+
and _alternative_import.rsplit(".", maxsplit=1)[-1].lower()
|
|
365
|
+
== _alternative_import.rsplit(".", maxsplit=1)[-1]
|
|
366
|
+
) or _alternative_import:
|
|
367
|
+
_alternative_import = f"`{_alternative_import}`"
|
|
375
368
|
|
|
376
369
|
components = [
|
|
377
370
|
_message,
|
|
378
371
|
f"Use {_alternative} instead." if _alternative else "",
|
|
379
|
-
f"Use
|
|
372
|
+
f"Use `{_alternative_import}` instead." if _alternative_import else "",
|
|
380
373
|
_addendum,
|
|
381
374
|
]
|
|
382
375
|
details = " ".join([component.strip() for component in components if component])
|
|
@@ -391,7 +384,7 @@ def deprecated(
|
|
|
391
384
|
else:
|
|
392
385
|
removal_str = ""
|
|
393
386
|
new_doc = f"""\
|
|
394
|
-
|
|
387
|
+
!!! deprecated "{since} {details} {removal_str}"
|
|
395
388
|
|
|
396
389
|
{old_doc}\
|
|
397
390
|
"""
|
|
@@ -427,35 +420,35 @@ def warn_deprecated(
|
|
|
427
420
|
) -> None:
|
|
428
421
|
"""Display a standardized deprecation.
|
|
429
422
|
|
|
430
|
-
|
|
431
|
-
since
|
|
423
|
+
Args:
|
|
424
|
+
since:
|
|
432
425
|
The release at which this API became deprecated.
|
|
433
|
-
message
|
|
426
|
+
message:
|
|
434
427
|
Override the default deprecation message. The %(since)s,
|
|
435
428
|
%(name)s, %(alternative)s, %(obj_type)s, %(addendum)s,
|
|
436
429
|
and %(removal)s format specifiers will be replaced by the
|
|
437
430
|
values of the respective arguments passed to this function.
|
|
438
|
-
name
|
|
431
|
+
name:
|
|
439
432
|
The name of the deprecated object.
|
|
440
|
-
alternative
|
|
433
|
+
alternative:
|
|
441
434
|
An alternative API that the user may use in place of the
|
|
442
435
|
deprecated API. The deprecation warning will tell the user
|
|
443
436
|
about this alternative if provided.
|
|
444
|
-
alternative_import:
|
|
437
|
+
alternative_import:
|
|
445
438
|
An alternative import that the user may use instead.
|
|
446
|
-
pending
|
|
447
|
-
If True
|
|
439
|
+
pending:
|
|
440
|
+
If `True`, uses a `PendingDeprecationWarning` instead of a
|
|
448
441
|
DeprecationWarning. Cannot be used together with removal.
|
|
449
|
-
obj_type
|
|
442
|
+
obj_type:
|
|
450
443
|
The object type being deprecated.
|
|
451
|
-
addendum
|
|
444
|
+
addendum:
|
|
452
445
|
Additional text appended directly to the final message.
|
|
453
|
-
removal
|
|
446
|
+
removal:
|
|
454
447
|
The expected removal version. With the default (an empty
|
|
455
448
|
string), a removal version is automatically computed from
|
|
456
449
|
since. Set to other Falsy values to not schedule a removal
|
|
457
450
|
date. Cannot be used together with pending.
|
|
458
|
-
package:
|
|
451
|
+
package:
|
|
459
452
|
The package of the deprecated object.
|
|
460
453
|
"""
|
|
461
454
|
if not pending:
|
|
@@ -471,7 +464,7 @@ def warn_deprecated(
|
|
|
471
464
|
if not message:
|
|
472
465
|
message = ""
|
|
473
466
|
package_ = (
|
|
474
|
-
package or name.split(".")[0].replace("_", "-")
|
|
467
|
+
package or name.split(".", maxsplit=1)[0].replace("_", "-")
|
|
475
468
|
if "." in name
|
|
476
469
|
else "LangChain"
|
|
477
470
|
)
|
|
@@ -490,7 +483,7 @@ def warn_deprecated(
|
|
|
490
483
|
message += f" and will be removed {removal}"
|
|
491
484
|
|
|
492
485
|
if alternative_import:
|
|
493
|
-
alt_package = alternative_import.split(".")[0].replace("_", "-")
|
|
486
|
+
alt_package = alternative_import.split(".", maxsplit=1)[0].replace("_", "-")
|
|
494
487
|
if alt_package == package_:
|
|
495
488
|
message += f". Use {alternative_import} instead."
|
|
496
489
|
else:
|
|
@@ -540,17 +533,24 @@ def rename_parameter(
|
|
|
540
533
|
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
|
|
541
534
|
"""Decorator indicating that parameter *old* of *func* is renamed to *new*.
|
|
542
535
|
|
|
543
|
-
The actual implementation of *func* should use *new*, not *old*.
|
|
544
|
-
|
|
545
|
-
|
|
536
|
+
The actual implementation of *func* should use *new*, not *old*. If *old* is passed
|
|
537
|
+
to *func*, a DeprecationWarning is emitted, and its value is used, even if *new* is
|
|
538
|
+
also passed by keyword.
|
|
546
539
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
540
|
+
Args:
|
|
541
|
+
since: The version in which the parameter was renamed.
|
|
542
|
+
removal: The version in which the old parameter will be removed.
|
|
543
|
+
old: The old parameter name.
|
|
544
|
+
new: The new parameter name.
|
|
550
545
|
|
|
551
|
-
|
|
552
|
-
|
|
546
|
+
Returns:
|
|
547
|
+
A decorator indicating that a parameter was renamed.
|
|
553
548
|
|
|
549
|
+
Example:
|
|
550
|
+
```python
|
|
551
|
+
@_api.rename_parameter("3.1", "bad_name", "good_name")
|
|
552
|
+
def func(good_name): ...
|
|
553
|
+
```
|
|
554
554
|
"""
|
|
555
555
|
|
|
556
556
|
def decorator(f: Callable[_P, _R]) -> Callable[_P, _R]:
|
langchain_core/_api/path.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from pathlib import Path
|
|
3
|
-
from typing import Optional, Union
|
|
4
3
|
|
|
5
4
|
HERE = Path(__file__).parent
|
|
6
5
|
|
|
@@ -9,22 +8,37 @@ PACKAGE_DIR = HERE.parent
|
|
|
9
8
|
SEPARATOR = os.sep
|
|
10
9
|
|
|
11
10
|
|
|
12
|
-
def get_relative_path(
|
|
13
|
-
file
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
def get_relative_path(file: Path | str, *, relative_to: Path = PACKAGE_DIR) -> str:
|
|
12
|
+
"""Get the path of the file as a relative path to the package directory.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
file: The file path to convert.
|
|
16
|
+
relative_to: The base path to make the file path relative to.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
The relative path as a string.
|
|
20
|
+
"""
|
|
16
21
|
if isinstance(file, str):
|
|
17
22
|
file = Path(file)
|
|
18
23
|
return str(file.relative_to(relative_to))
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
def as_import_path(
|
|
22
|
-
file:
|
|
27
|
+
file: Path | str,
|
|
23
28
|
*,
|
|
24
|
-
suffix:
|
|
29
|
+
suffix: str | None = None,
|
|
25
30
|
relative_to: Path = PACKAGE_DIR,
|
|
26
31
|
) -> str:
|
|
27
|
-
"""Path of the file as a LangChain import exclude langchain top namespace.
|
|
32
|
+
"""Path of the file as a LangChain import exclude langchain top namespace.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
file: The file path to convert.
|
|
36
|
+
suffix: An optional suffix to append to the import path.
|
|
37
|
+
relative_to: The base path to make the file path relative to.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
The import path as a string.
|
|
41
|
+
"""
|
|
28
42
|
if isinstance(file, str):
|
|
29
43
|
file = Path(file)
|
|
30
44
|
path = get_relative_path(file, relative_to=relative_to)
|
langchain_core/_import_utils.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
from importlib import import_module
|
|
2
|
-
from typing import Union
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
def import_attr(
|
|
6
5
|
attr_name: str,
|
|
7
|
-
module_name:
|
|
8
|
-
package:
|
|
6
|
+
module_name: str | None,
|
|
7
|
+
package: str | None,
|
|
9
8
|
) -> object:
|
|
10
9
|
"""Import an attribute from a module located in a package.
|
|
11
10
|
|
|
@@ -14,9 +13,16 @@ def import_attr(
|
|
|
14
13
|
|
|
15
14
|
Args:
|
|
16
15
|
attr_name: The name of the attribute to import.
|
|
17
|
-
module_name: The name of the module to import from. If None
|
|
16
|
+
module_name: The name of the module to import from. If `None`, the attribute
|
|
18
17
|
is imported from the package itself.
|
|
19
18
|
package: The name of the package where the module is located.
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
ImportError: If the module cannot be found.
|
|
22
|
+
AttributeError: If the attribute does not exist in the module or package.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
The imported attribute.
|
|
20
26
|
"""
|
|
21
27
|
if module_name == "__module__" or module_name is None:
|
|
22
28
|
try:
|