langchain-core 1.0.0a8__py3-none-any.whl → 1.0.0rc2__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 +0 -1
- langchain_core/_api/beta_decorator.py +17 -20
- langchain_core/_api/deprecation.py +30 -35
- langchain_core/_import_utils.py +1 -1
- langchain_core/agents.py +10 -9
- langchain_core/caches.py +46 -56
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +232 -243
- langchain_core/callbacks/file.py +33 -33
- langchain_core/callbacks/manager.py +353 -416
- langchain_core/callbacks/stdout.py +21 -22
- langchain_core/callbacks/streaming_stdout.py +32 -32
- langchain_core/callbacks/usage.py +54 -51
- langchain_core/chat_history.py +43 -58
- langchain_core/document_loaders/base.py +21 -21
- langchain_core/document_loaders/langsmith.py +22 -22
- langchain_core/documents/__init__.py +0 -1
- langchain_core/documents/base.py +46 -49
- langchain_core/documents/transformers.py +28 -29
- langchain_core/embeddings/fake.py +50 -54
- langchain_core/example_selectors/semantic_similarity.py +4 -6
- langchain_core/exceptions.py +7 -8
- langchain_core/indexing/api.py +19 -25
- langchain_core/indexing/base.py +24 -24
- langchain_core/language_models/__init__.py +11 -27
- langchain_core/language_models/_utils.py +53 -54
- langchain_core/language_models/base.py +30 -24
- langchain_core/language_models/chat_models.py +123 -148
- langchain_core/language_models/fake_chat_models.py +7 -7
- langchain_core/language_models/llms.py +14 -16
- langchain_core/load/dump.py +3 -4
- langchain_core/load/load.py +7 -16
- langchain_core/load/serializable.py +37 -36
- langchain_core/messages/__init__.py +1 -16
- langchain_core/messages/ai.py +122 -123
- langchain_core/messages/base.py +31 -31
- langchain_core/messages/block_translators/__init__.py +17 -17
- langchain_core/messages/block_translators/anthropic.py +3 -3
- langchain_core/messages/block_translators/bedrock_converse.py +3 -3
- langchain_core/messages/block_translators/google_genai.py +5 -4
- 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 +3 -3
- langchain_core/messages/block_translators/openai.py +5 -5
- langchain_core/messages/chat.py +2 -6
- langchain_core/messages/content.py +222 -209
- langchain_core/messages/function.py +6 -10
- langchain_core/messages/human.py +17 -24
- langchain_core/messages/modifier.py +2 -2
- langchain_core/messages/system.py +12 -22
- langchain_core/messages/tool.py +53 -69
- langchain_core/messages/utils.py +399 -417
- langchain_core/output_parsers/__init__.py +1 -14
- langchain_core/output_parsers/base.py +46 -47
- langchain_core/output_parsers/json.py +3 -4
- langchain_core/output_parsers/list.py +2 -2
- langchain_core/output_parsers/openai_functions.py +46 -44
- langchain_core/output_parsers/openai_tools.py +11 -16
- langchain_core/output_parsers/pydantic.py +10 -11
- langchain_core/output_parsers/string.py +2 -2
- langchain_core/output_parsers/transform.py +2 -2
- langchain_core/output_parsers/xml.py +1 -1
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +14 -14
- langchain_core/outputs/generation.py +6 -6
- langchain_core/outputs/llm_result.py +5 -5
- langchain_core/prompt_values.py +11 -11
- langchain_core/prompts/__init__.py +3 -23
- langchain_core/prompts/base.py +33 -38
- langchain_core/prompts/chat.py +222 -229
- langchain_core/prompts/dict.py +3 -3
- langchain_core/prompts/few_shot.py +76 -83
- langchain_core/prompts/few_shot_with_templates.py +7 -9
- langchain_core/prompts/image.py +12 -14
- langchain_core/prompts/loading.py +1 -1
- langchain_core/prompts/message.py +3 -3
- langchain_core/prompts/prompt.py +20 -23
- langchain_core/prompts/string.py +20 -8
- langchain_core/prompts/structured.py +26 -27
- langchain_core/rate_limiters.py +50 -58
- langchain_core/retrievers.py +41 -182
- langchain_core/runnables/base.py +565 -597
- langchain_core/runnables/branch.py +8 -8
- langchain_core/runnables/config.py +37 -44
- langchain_core/runnables/configurable.py +9 -10
- langchain_core/runnables/fallbacks.py +9 -9
- langchain_core/runnables/graph.py +46 -50
- langchain_core/runnables/graph_ascii.py +19 -18
- langchain_core/runnables/graph_mermaid.py +20 -31
- langchain_core/runnables/graph_png.py +7 -7
- langchain_core/runnables/history.py +22 -22
- langchain_core/runnables/passthrough.py +11 -11
- langchain_core/runnables/retry.py +3 -3
- langchain_core/runnables/router.py +2 -2
- langchain_core/runnables/schema.py +33 -33
- langchain_core/runnables/utils.py +30 -34
- langchain_core/stores.py +72 -102
- langchain_core/sys_info.py +27 -29
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +70 -71
- langchain_core/tools/convert.py +100 -104
- langchain_core/tools/render.py +9 -9
- langchain_core/tools/retriever.py +7 -7
- langchain_core/tools/simple.py +6 -7
- langchain_core/tools/structured.py +18 -24
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/base.py +35 -35
- langchain_core/tracers/context.py +12 -17
- langchain_core/tracers/event_stream.py +3 -3
- langchain_core/tracers/langchain.py +8 -8
- langchain_core/tracers/log_stream.py +17 -18
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +2 -2
- langchain_core/tracers/schemas.py +0 -129
- langchain_core/tracers/stdout.py +1 -2
- langchain_core/utils/__init__.py +1 -1
- langchain_core/utils/aiter.py +32 -32
- langchain_core/utils/env.py +5 -5
- langchain_core/utils/function_calling.py +59 -154
- langchain_core/utils/html.py +4 -4
- langchain_core/utils/input.py +3 -3
- langchain_core/utils/interactive_env.py +1 -1
- langchain_core/utils/iter.py +20 -20
- langchain_core/utils/json.py +1 -1
- langchain_core/utils/json_schema.py +2 -2
- langchain_core/utils/mustache.py +5 -5
- langchain_core/utils/pydantic.py +17 -17
- langchain_core/utils/strings.py +5 -5
- langchain_core/utils/utils.py +25 -28
- langchain_core/vectorstores/base.py +55 -87
- langchain_core/vectorstores/in_memory.py +83 -85
- langchain_core/vectorstores/utils.py +2 -2
- langchain_core/version.py +1 -1
- {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc2.dist-info}/METADATA +23 -11
- langchain_core-1.0.0rc2.dist-info/RECORD +172 -0
- langchain_core/memory.py +0 -120
- 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-1.0.0a8.dist-info/RECORD +0 -176
- {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc2.dist-info}/WHEEL +0 -0
langchain_core/load/load.py
CHANGED
|
@@ -63,16 +63,13 @@ class Reviver:
|
|
|
63
63
|
Args:
|
|
64
64
|
secrets_map: A map of secrets to load. If a secret is not found in
|
|
65
65
|
the map, it will be loaded from the environment if `secrets_from_env`
|
|
66
|
-
is True.
|
|
66
|
+
is True.
|
|
67
67
|
valid_namespaces: A list of additional namespaces (modules)
|
|
68
|
-
to allow to be deserialized.
|
|
68
|
+
to allow to be deserialized.
|
|
69
69
|
secrets_from_env: Whether to load secrets from the environment.
|
|
70
|
-
Defaults to True.
|
|
71
70
|
additional_import_mappings: A dictionary of additional namespace mappings
|
|
72
71
|
You can use this to override default mappings or add new mappings.
|
|
73
|
-
Defaults to None.
|
|
74
72
|
ignore_unserializable_fields: Whether to ignore unserializable fields.
|
|
75
|
-
Defaults to False.
|
|
76
73
|
"""
|
|
77
74
|
self.secrets_from_env = secrets_from_env
|
|
78
75
|
self.secrets_map = secrets_map or {}
|
|
@@ -107,7 +104,7 @@ class Reviver:
|
|
|
107
104
|
ValueError: If trying to deserialize something that cannot
|
|
108
105
|
be deserialized in the current version of langchain-core.
|
|
109
106
|
NotImplementedError: If the object is not implemented and
|
|
110
|
-
|
|
107
|
+
`ignore_unserializable_fields` is False.
|
|
111
108
|
"""
|
|
112
109
|
if (
|
|
113
110
|
value.get("lc") == 1
|
|
@@ -200,16 +197,13 @@ def loads(
|
|
|
200
197
|
text: The string to load.
|
|
201
198
|
secrets_map: A map of secrets to load. If a secret is not found in
|
|
202
199
|
the map, it will be loaded from the environment if `secrets_from_env`
|
|
203
|
-
is True.
|
|
200
|
+
is True.
|
|
204
201
|
valid_namespaces: A list of additional namespaces (modules)
|
|
205
|
-
to allow to be deserialized.
|
|
202
|
+
to allow to be deserialized.
|
|
206
203
|
secrets_from_env: Whether to load secrets from the environment.
|
|
207
|
-
Defaults to True.
|
|
208
204
|
additional_import_mappings: A dictionary of additional namespace mappings
|
|
209
205
|
You can use this to override default mappings or add new mappings.
|
|
210
|
-
Defaults to None.
|
|
211
206
|
ignore_unserializable_fields: Whether to ignore unserializable fields.
|
|
212
|
-
Defaults to False.
|
|
213
207
|
|
|
214
208
|
Returns:
|
|
215
209
|
Revived LangChain objects.
|
|
@@ -245,16 +239,13 @@ def load(
|
|
|
245
239
|
obj: The object to load.
|
|
246
240
|
secrets_map: A map of secrets to load. If a secret is not found in
|
|
247
241
|
the map, it will be loaded from the environment if `secrets_from_env`
|
|
248
|
-
is True.
|
|
242
|
+
is True.
|
|
249
243
|
valid_namespaces: A list of additional namespaces (modules)
|
|
250
|
-
to allow to be deserialized.
|
|
244
|
+
to allow to be deserialized.
|
|
251
245
|
secrets_from_env: Whether to load secrets from the environment.
|
|
252
|
-
Defaults to True.
|
|
253
246
|
additional_import_mappings: A dictionary of additional namespace mappings
|
|
254
247
|
You can use this to override default mappings or add new mappings.
|
|
255
|
-
Defaults to None.
|
|
256
248
|
ignore_unserializable_fields: Whether to ignore unserializable fields.
|
|
257
|
-
Defaults to False.
|
|
258
249
|
|
|
259
250
|
Returns:
|
|
260
251
|
Revived LangChain objects.
|
|
@@ -25,16 +25,16 @@ class BaseSerialized(TypedDict):
|
|
|
25
25
|
id: list[str]
|
|
26
26
|
"""The unique identifier of the object."""
|
|
27
27
|
name: NotRequired[str]
|
|
28
|
-
"""The name of the object.
|
|
28
|
+
"""The name of the object."""
|
|
29
29
|
graph: NotRequired[dict[str, Any]]
|
|
30
|
-
"""The graph of the object.
|
|
30
|
+
"""The graph of the object."""
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
class SerializedConstructor(BaseSerialized):
|
|
34
34
|
"""Serialized constructor."""
|
|
35
35
|
|
|
36
36
|
type: Literal["constructor"]
|
|
37
|
-
"""The type of the object. Must be
|
|
37
|
+
"""The type of the object. Must be `'constructor'`."""
|
|
38
38
|
kwargs: dict[str, Any]
|
|
39
39
|
"""The constructor arguments."""
|
|
40
40
|
|
|
@@ -43,16 +43,16 @@ class SerializedSecret(BaseSerialized):
|
|
|
43
43
|
"""Serialized secret."""
|
|
44
44
|
|
|
45
45
|
type: Literal["secret"]
|
|
46
|
-
"""The type of the object. Must be
|
|
46
|
+
"""The type of the object. Must be `'secret'`."""
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
class SerializedNotImplemented(BaseSerialized):
|
|
50
50
|
"""Serialized not implemented."""
|
|
51
51
|
|
|
52
52
|
type: Literal["not_implemented"]
|
|
53
|
-
"""The type of the object. Must be
|
|
53
|
+
"""The type of the object. Must be `'not_implemented'`."""
|
|
54
54
|
repr: str | None
|
|
55
|
-
"""The representation of the object.
|
|
55
|
+
"""The representation of the object."""
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
def try_neq_default(value: Any, key: str, model: BaseModel) -> bool:
|
|
@@ -61,7 +61,7 @@ def try_neq_default(value: Any, key: str, model: BaseModel) -> bool:
|
|
|
61
61
|
Args:
|
|
62
62
|
value: The value.
|
|
63
63
|
key: The key.
|
|
64
|
-
model: The
|
|
64
|
+
model: The Pydantic model.
|
|
65
65
|
|
|
66
66
|
Returns:
|
|
67
67
|
Whether the value is different from the default.
|
|
@@ -92,19 +92,19 @@ class Serializable(BaseModel, ABC):
|
|
|
92
92
|
|
|
93
93
|
It relies on the following methods and properties:
|
|
94
94
|
|
|
95
|
-
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
107
|
-
|
|
95
|
+
- `is_lc_serializable`: Is this class serializable?
|
|
96
|
+
By design, even if a class inherits from `Serializable`, it is not serializable
|
|
97
|
+
by default. This is to prevent accidental serialization of objects that should
|
|
98
|
+
not be serialized.
|
|
99
|
+
- `get_lc_namespace`: Get the namespace of the LangChain object.
|
|
100
|
+
During deserialization, this namespace is used to identify
|
|
101
|
+
the correct class to instantiate.
|
|
102
|
+
Please see the `Reviver` class in `langchain_core.load.load` for more details.
|
|
103
|
+
During deserialization an additional mapping is handle classes that have moved
|
|
104
|
+
or been renamed across package versions.
|
|
105
|
+
- `lc_secrets`: A map of constructor argument names to secret ids.
|
|
106
|
+
- `lc_attributes`: List of additional attribute names that should be included
|
|
107
|
+
as part of the serialized representation.
|
|
108
108
|
"""
|
|
109
109
|
|
|
110
110
|
# Remove default BaseModel init docstring.
|
|
@@ -116,24 +116,24 @@ class Serializable(BaseModel, ABC):
|
|
|
116
116
|
def is_lc_serializable(cls) -> bool:
|
|
117
117
|
"""Is this class serializable?
|
|
118
118
|
|
|
119
|
-
By design, even if a class inherits from Serializable
|
|
120
|
-
default. This is to prevent accidental serialization of objects that should
|
|
121
|
-
be serialized.
|
|
119
|
+
By design, even if a class inherits from `Serializable`, it is not serializable
|
|
120
|
+
by default. This is to prevent accidental serialization of objects that should
|
|
121
|
+
not be serialized.
|
|
122
122
|
|
|
123
123
|
Returns:
|
|
124
|
-
Whether the class is serializable. Default is False
|
|
124
|
+
Whether the class is serializable. Default is `False`.
|
|
125
125
|
"""
|
|
126
126
|
return False
|
|
127
127
|
|
|
128
128
|
@classmethod
|
|
129
129
|
def get_lc_namespace(cls) -> list[str]:
|
|
130
|
-
"""Get the namespace of the
|
|
130
|
+
"""Get the namespace of the LangChain object.
|
|
131
131
|
|
|
132
132
|
For example, if the class is `langchain.llms.openai.OpenAI`, then the
|
|
133
|
-
namespace is ["langchain", "llms", "openai"]
|
|
133
|
+
namespace is `["langchain", "llms", "openai"]`
|
|
134
134
|
|
|
135
135
|
Returns:
|
|
136
|
-
The namespace
|
|
136
|
+
The namespace.
|
|
137
137
|
"""
|
|
138
138
|
return cls.__module__.split(".")
|
|
139
139
|
|
|
@@ -141,8 +141,7 @@ class Serializable(BaseModel, ABC):
|
|
|
141
141
|
def lc_secrets(self) -> dict[str, str]:
|
|
142
142
|
"""A map of constructor argument names to secret ids.
|
|
143
143
|
|
|
144
|
-
For example,
|
|
145
|
-
{"openai_api_key": "OPENAI_API_KEY"}
|
|
144
|
+
For example, `{"openai_api_key": "OPENAI_API_KEY"}`
|
|
146
145
|
"""
|
|
147
146
|
return {}
|
|
148
147
|
|
|
@@ -151,6 +150,7 @@ class Serializable(BaseModel, ABC):
|
|
|
151
150
|
"""List of attribute names that should be included in the serialized kwargs.
|
|
152
151
|
|
|
153
152
|
These attributes must be accepted by the constructor.
|
|
153
|
+
|
|
154
154
|
Default is an empty dictionary.
|
|
155
155
|
"""
|
|
156
156
|
return {}
|
|
@@ -161,8 +161,9 @@ class Serializable(BaseModel, ABC):
|
|
|
161
161
|
|
|
162
162
|
The unique identifier is a list of strings that describes the path
|
|
163
163
|
to the object.
|
|
164
|
+
|
|
164
165
|
For example, for the class `langchain.llms.openai.OpenAI`, the id is
|
|
165
|
-
["langchain", "llms", "openai", "OpenAI"]
|
|
166
|
+
`["langchain", "llms", "openai", "OpenAI"]`.
|
|
166
167
|
"""
|
|
167
168
|
# Pydantic generics change the class name. So we need to do the following
|
|
168
169
|
if (
|
|
@@ -193,7 +194,7 @@ class Serializable(BaseModel, ABC):
|
|
|
193
194
|
ValueError: If the class has deprecated attributes.
|
|
194
195
|
|
|
195
196
|
Returns:
|
|
196
|
-
A json serializable object or a SerializedNotImplemented object.
|
|
197
|
+
A json serializable object or a `SerializedNotImplemented` object.
|
|
197
198
|
"""
|
|
198
199
|
if not self.is_lc_serializable():
|
|
199
200
|
return self.to_json_not_implemented()
|
|
@@ -268,7 +269,7 @@ class Serializable(BaseModel, ABC):
|
|
|
268
269
|
"""Serialize a "not implemented" object.
|
|
269
270
|
|
|
270
271
|
Returns:
|
|
271
|
-
SerializedNotImplemented
|
|
272
|
+
`SerializedNotImplemented`.
|
|
272
273
|
"""
|
|
273
274
|
return to_json_not_implemented(self)
|
|
274
275
|
|
|
@@ -283,8 +284,8 @@ def _is_field_useful(inst: Serializable, key: str, value: Any) -> bool:
|
|
|
283
284
|
|
|
284
285
|
Returns:
|
|
285
286
|
Whether the field is useful. If the field is required, it is useful.
|
|
286
|
-
If the field is not required, it is useful if the value is not None
|
|
287
|
-
If the field is not required and the value is None
|
|
287
|
+
If the field is not required, it is useful if the value is not `None`.
|
|
288
|
+
If the field is not required and the value is `None`, it is useful if the
|
|
288
289
|
default value is different from the value.
|
|
289
290
|
"""
|
|
290
291
|
field = type(inst).model_fields.get(key)
|
|
@@ -343,10 +344,10 @@ def to_json_not_implemented(obj: object) -> SerializedNotImplemented:
|
|
|
343
344
|
"""Serialize a "not implemented" object.
|
|
344
345
|
|
|
345
346
|
Args:
|
|
346
|
-
obj:
|
|
347
|
+
obj: Object to serialize.
|
|
347
348
|
|
|
348
349
|
Returns:
|
|
349
|
-
SerializedNotImplemented
|
|
350
|
+
`SerializedNotImplemented`
|
|
350
351
|
"""
|
|
351
352
|
id_: list[str] = []
|
|
352
353
|
try:
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
"""**Messages** are objects used in prompts and chat conversations.
|
|
2
|
-
|
|
3
|
-
**Class hierarchy:**
|
|
4
|
-
|
|
5
|
-
.. code-block::
|
|
6
|
-
|
|
7
|
-
BaseMessage --> SystemMessage, AIMessage, HumanMessage, ChatMessage, FunctionMessage, ToolMessage
|
|
8
|
-
--> BaseMessageChunk --> SystemMessageChunk, AIMessageChunk, HumanMessageChunk, ChatMessageChunk, FunctionMessageChunk, ToolMessageChunk
|
|
9
|
-
|
|
10
|
-
**Main helpers:**
|
|
11
|
-
|
|
12
|
-
.. code-block::
|
|
13
|
-
|
|
14
|
-
ChatPromptTemplate
|
|
15
|
-
|
|
16
|
-
""" # noqa: E501
|
|
1
|
+
"""**Messages** are objects used in prompts and chat conversations."""
|
|
17
2
|
|
|
18
3
|
from typing import TYPE_CHECKING
|
|
19
4
|
|