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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"""Module contains typedefs that are used with
|
|
1
|
+
"""Module contains typedefs that are used with `Runnable` objects."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Literal
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
6
6
|
|
|
7
7
|
from typing_extensions import NotRequired, TypedDict
|
|
8
8
|
|
|
@@ -14,118 +14,125 @@ class EventData(TypedDict, total=False):
|
|
|
14
14
|
"""Data associated with a streaming event."""
|
|
15
15
|
|
|
16
16
|
input: Any
|
|
17
|
-
"""The input passed to the Runnable that generated the event.
|
|
17
|
+
"""The input passed to the `Runnable` that generated the event.
|
|
18
18
|
|
|
19
|
-
Inputs will sometimes be available at the *START* of the Runnable
|
|
20
|
-
sometimes at the *END* of the Runnable
|
|
19
|
+
Inputs will sometimes be available at the *START* of the `Runnable`, and
|
|
20
|
+
sometimes at the *END* of the `Runnable`.
|
|
21
21
|
|
|
22
|
-
If a Runnable is able to stream its inputs, then its input by definition
|
|
23
|
-
won't be known until the *END* of the Runnable when it has finished streaming
|
|
22
|
+
If a `Runnable` is able to stream its inputs, then its input by definition
|
|
23
|
+
won't be known until the *END* of the `Runnable` when it has finished streaming
|
|
24
24
|
its inputs.
|
|
25
25
|
"""
|
|
26
|
+
error: NotRequired[BaseException]
|
|
27
|
+
"""The error that occurred during the execution of the `Runnable`.
|
|
28
|
+
|
|
29
|
+
This field is only available if the `Runnable` raised an exception.
|
|
30
|
+
|
|
31
|
+
!!! version-added "Added in version 1.0.0"
|
|
32
|
+
"""
|
|
26
33
|
output: Any
|
|
27
|
-
"""The output of the Runnable that generated the event.
|
|
34
|
+
"""The output of the `Runnable` that generated the event.
|
|
28
35
|
|
|
29
|
-
Outputs will only be available at the *END* of the Runnable
|
|
36
|
+
Outputs will only be available at the *END* of the `Runnable`.
|
|
30
37
|
|
|
31
|
-
For most
|
|
32
|
-
though there might be some exceptions for special cased
|
|
38
|
+
For most `Runnable` objects, this field can be inferred from the `chunk` field,
|
|
39
|
+
though there might be some exceptions for special a cased `Runnable` (e.g., like
|
|
33
40
|
chat models), which may return more information.
|
|
34
41
|
"""
|
|
35
42
|
chunk: Any
|
|
36
43
|
"""A streaming chunk from the output that generated the event.
|
|
37
44
|
|
|
38
45
|
chunks support addition in general, and adding them up should result
|
|
39
|
-
in the output of the Runnable that generated the event.
|
|
46
|
+
in the output of the `Runnable` that generated the event.
|
|
40
47
|
"""
|
|
41
48
|
|
|
42
49
|
|
|
43
50
|
class BaseStreamEvent(TypedDict):
|
|
44
51
|
"""Streaming event.
|
|
45
52
|
|
|
46
|
-
Schema of a streaming event which is produced from the astream_events method.
|
|
53
|
+
Schema of a streaming event which is produced from the `astream_events` method.
|
|
47
54
|
|
|
48
55
|
Example:
|
|
49
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
56
|
+
```python
|
|
57
|
+
from langchain_core.runnables import RunnableLambda
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def reverse(s: str) -> str:
|
|
61
|
+
return s[::-1]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
chain = RunnableLambda(func=reverse)
|
|
65
|
+
|
|
66
|
+
events = [event async for event in chain.astream_events("hello")]
|
|
67
|
+
|
|
68
|
+
# Will produce the following events
|
|
69
|
+
# (where some fields have been omitted for brevity):
|
|
70
|
+
[
|
|
71
|
+
{
|
|
72
|
+
"data": {"input": "hello"},
|
|
73
|
+
"event": "on_chain_start",
|
|
74
|
+
"metadata": {},
|
|
75
|
+
"name": "reverse",
|
|
76
|
+
"tags": [],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"data": {"chunk": "olleh"},
|
|
80
|
+
"event": "on_chain_stream",
|
|
81
|
+
"metadata": {},
|
|
82
|
+
"name": "reverse",
|
|
83
|
+
"tags": [],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"data": {"output": "olleh"},
|
|
87
|
+
"event": "on_chain_end",
|
|
88
|
+
"metadata": {},
|
|
89
|
+
"name": "reverse",
|
|
90
|
+
"tags": [],
|
|
91
|
+
},
|
|
92
|
+
]
|
|
93
|
+
```
|
|
87
94
|
"""
|
|
88
95
|
|
|
89
96
|
event: str
|
|
90
|
-
"""Event names are of the format: on_[runnable_type]_(start|stream|end)
|
|
97
|
+
"""Event names are of the format: `on_[runnable_type]_(start|stream|end)`.
|
|
91
98
|
|
|
92
99
|
Runnable types are one of:
|
|
93
100
|
|
|
94
101
|
- **llm** - used by non chat models
|
|
95
102
|
- **chat_model** - used by chat models
|
|
96
|
-
- **prompt** -- e.g., ChatPromptTemplate
|
|
97
|
-
- **tool** -- from tools defined via
|
|
98
|
-
from Tool
|
|
99
|
-
- **chain** - most
|
|
103
|
+
- **prompt** -- e.g., `ChatPromptTemplate`
|
|
104
|
+
- **tool** -- from tools defined via `@tool` decorator or inheriting
|
|
105
|
+
from `Tool`/`BaseTool`
|
|
106
|
+
- **chain** - most `Runnable` objects are of this type
|
|
100
107
|
|
|
101
108
|
Further, the events are categorized as one of:
|
|
102
109
|
|
|
103
|
-
- **start** - when the Runnable starts
|
|
104
|
-
- **stream** - when the Runnable is streaming
|
|
105
|
-
- **end* - when the Runnable ends
|
|
110
|
+
- **start** - when the `Runnable` starts
|
|
111
|
+
- **stream** - when the `Runnable` is streaming
|
|
112
|
+
- **end* - when the `Runnable` ends
|
|
106
113
|
|
|
107
114
|
start, stream and end are associated with slightly different `data` payload.
|
|
108
115
|
|
|
109
116
|
Please see the documentation for `EventData` for more details.
|
|
110
117
|
"""
|
|
111
118
|
run_id: str
|
|
112
|
-
"""An randomly generated ID to keep track of the execution of the given Runnable
|
|
119
|
+
"""An randomly generated ID to keep track of the execution of the given `Runnable`.
|
|
113
120
|
|
|
114
|
-
Each child Runnable that gets invoked as part of the execution of a parent
|
|
115
|
-
is assigned its own unique ID.
|
|
121
|
+
Each child `Runnable` that gets invoked as part of the execution of a parent
|
|
122
|
+
`Runnable` is assigned its own unique ID.
|
|
116
123
|
"""
|
|
117
124
|
tags: NotRequired[list[str]]
|
|
118
|
-
"""Tags associated with the Runnable that generated this event.
|
|
125
|
+
"""Tags associated with the `Runnable` that generated this event.
|
|
119
126
|
|
|
120
|
-
Tags are always inherited from parent
|
|
127
|
+
Tags are always inherited from parent `Runnable` objects.
|
|
121
128
|
|
|
122
|
-
Tags can either be bound to a Runnable using `.with_config({"tags": ["hello"]})`
|
|
129
|
+
Tags can either be bound to a `Runnable` using `.with_config({"tags": ["hello"]})`
|
|
123
130
|
or passed at run time using `.astream_events(..., {"tags": ["hello"]})`.
|
|
124
131
|
"""
|
|
125
132
|
metadata: NotRequired[dict[str, Any]]
|
|
126
|
-
"""Metadata associated with the Runnable that generated this event.
|
|
133
|
+
"""Metadata associated with the `Runnable` that generated this event.
|
|
127
134
|
|
|
128
|
-
Metadata can either be bound to a Runnable using
|
|
135
|
+
Metadata can either be bound to a `Runnable` using
|
|
129
136
|
|
|
130
137
|
`.with_config({"metadata": { "foo": "bar" }})`
|
|
131
138
|
|
|
@@ -139,8 +146,8 @@ class BaseStreamEvent(TypedDict):
|
|
|
139
146
|
|
|
140
147
|
Root Events will have an empty list.
|
|
141
148
|
|
|
142
|
-
For example, if a Runnable A calls Runnable B, then the event generated by
|
|
143
|
-
B will have Runnable A's ID in the parent_ids field.
|
|
149
|
+
For example, if a `Runnable` A calls `Runnable` B, then the event generated by
|
|
150
|
+
`Runnable` B will have `Runnable` A's ID in the `parent_ids` field.
|
|
144
151
|
|
|
145
152
|
The order of the parent IDs is from the root parent to the immediate parent.
|
|
146
153
|
|
|
@@ -157,13 +164,13 @@ class StandardStreamEvent(BaseStreamEvent):
|
|
|
157
164
|
The contents of the event data depend on the event type.
|
|
158
165
|
"""
|
|
159
166
|
name: str
|
|
160
|
-
"""The name of the Runnable that generated the event."""
|
|
167
|
+
"""The name of the `Runnable` that generated the event."""
|
|
161
168
|
|
|
162
169
|
|
|
163
170
|
class CustomStreamEvent(BaseStreamEvent):
|
|
164
171
|
"""Custom stream event created by the user.
|
|
165
172
|
|
|
166
|
-
|
|
173
|
+
!!! version-added "Added in version 0.2.15"
|
|
167
174
|
"""
|
|
168
175
|
|
|
169
176
|
# Overwrite the event field to be more specific.
|
|
@@ -175,4 +182,4 @@ class CustomStreamEvent(BaseStreamEvent):
|
|
|
175
182
|
"""The data associated with the event. Free form and can be anything."""
|
|
176
183
|
|
|
177
184
|
|
|
178
|
-
StreamEvent =
|
|
185
|
+
StreamEvent = StandardStreamEvent | CustomStreamEvent
|