langchain 1.0.0a12__py3-none-any.whl → 1.0.4__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.
- langchain/__init__.py +1 -1
- langchain/agents/__init__.py +7 -1
- langchain/agents/factory.py +722 -226
- langchain/agents/middleware/__init__.py +36 -9
- langchain/agents/middleware/_execution.py +388 -0
- langchain/agents/middleware/_redaction.py +350 -0
- langchain/agents/middleware/context_editing.py +46 -17
- langchain/agents/middleware/file_search.py +382 -0
- langchain/agents/middleware/human_in_the_loop.py +220 -173
- langchain/agents/middleware/model_call_limit.py +43 -10
- langchain/agents/middleware/model_fallback.py +79 -36
- langchain/agents/middleware/pii.py +68 -504
- langchain/agents/middleware/shell_tool.py +718 -0
- langchain/agents/middleware/summarization.py +2 -2
- langchain/agents/middleware/{planning.py → todo.py} +35 -16
- langchain/agents/middleware/tool_call_limit.py +308 -114
- langchain/agents/middleware/tool_emulator.py +200 -0
- langchain/agents/middleware/tool_retry.py +384 -0
- langchain/agents/middleware/tool_selection.py +25 -21
- langchain/agents/middleware/types.py +714 -257
- langchain/agents/structured_output.py +37 -27
- langchain/chat_models/__init__.py +7 -1
- langchain/chat_models/base.py +192 -190
- langchain/embeddings/__init__.py +13 -3
- langchain/embeddings/base.py +49 -29
- langchain/messages/__init__.py +50 -1
- langchain/tools/__init__.py +9 -7
- langchain/tools/tool_node.py +16 -1174
- langchain-1.0.4.dist-info/METADATA +92 -0
- langchain-1.0.4.dist-info/RECORD +34 -0
- langchain/_internal/__init__.py +0 -0
- langchain/_internal/_documents.py +0 -35
- langchain/_internal/_lazy_import.py +0 -35
- langchain/_internal/_prompts.py +0 -158
- langchain/_internal/_typing.py +0 -70
- langchain/_internal/_utils.py +0 -7
- langchain/agents/_internal/__init__.py +0 -1
- langchain/agents/_internal/_typing.py +0 -13
- langchain/agents/middleware/prompt_caching.py +0 -86
- langchain/documents/__init__.py +0 -7
- langchain/embeddings/cache.py +0 -361
- langchain/storage/__init__.py +0 -22
- langchain/storage/encoder_backed.py +0 -123
- langchain/storage/exceptions.py +0 -5
- langchain/storage/in_memory.py +0 -13
- langchain-1.0.0a12.dist-info/METADATA +0 -122
- langchain-1.0.0a12.dist-info/RECORD +0 -43
- {langchain-1.0.0a12.dist-info → langchain-1.0.4.dist-info}/WHEEL +0 -0
- {langchain-1.0.0a12.dist-info → langchain-1.0.4.dist-info}/licenses/LICENSE +0 -0
langchain/embeddings/__init__.py
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
"""Embeddings.
|
|
1
|
+
"""Embeddings models.
|
|
2
|
+
|
|
3
|
+
!!! warning "Reference docs"
|
|
4
|
+
This page contains **reference documentation** for Embeddings. See
|
|
5
|
+
[the docs](https://docs.langchain.com/oss/python/langchain/retrieval#embedding-models)
|
|
6
|
+
for conceptual guides, tutorials, and examples on using Embeddings.
|
|
7
|
+
|
|
8
|
+
!!! warning "Modules moved"
|
|
9
|
+
With the release of `langchain 1.0.0`, several embeddings modules were moved to
|
|
10
|
+
`langchain-classic`, such as `CacheBackedEmbeddings` and all community
|
|
11
|
+
embeddings. See [list](https://github.com/langchain-ai/langchain/blob/bdf1cd383ce36dc18381a3bf3fb0a579337a32b5/libs/langchain/langchain/embeddings/__init__.py)
|
|
12
|
+
of moved modules to inform your migration.
|
|
13
|
+
"""
|
|
2
14
|
|
|
3
15
|
from langchain_core.embeddings import Embeddings
|
|
4
16
|
|
|
5
17
|
from langchain.embeddings.base import init_embeddings
|
|
6
|
-
from langchain.embeddings.cache import CacheBackedEmbeddings
|
|
7
18
|
|
|
8
19
|
__all__ = [
|
|
9
|
-
"CacheBackedEmbeddings",
|
|
10
20
|
"Embeddings",
|
|
11
21
|
"init_embeddings",
|
|
12
22
|
]
|
langchain/embeddings/base.py
CHANGED
|
@@ -35,13 +35,13 @@ def _parse_model_string(model_name: str) -> tuple[str, str]:
|
|
|
35
35
|
Returns:
|
|
36
36
|
A tuple of (provider, model_name)
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
```python
|
|
39
|
+
_parse_model_string("openai:text-embedding-3-small")
|
|
40
|
+
# Returns: ("openai", "text-embedding-3-small")
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_parse_model_string("bedrock:amazon.titan-embed-text-v1")
|
|
44
|
-
# Returns: ("bedrock", "amazon.titan-embed-text-v1")
|
|
42
|
+
_parse_model_string("bedrock:amazon.titan-embed-text-v1")
|
|
43
|
+
# Returns: ("bedrock", "amazon.titan-embed-text-v1")
|
|
44
|
+
```
|
|
45
45
|
|
|
46
46
|
Raises:
|
|
47
47
|
ValueError: If the model string is not in the correct format or
|
|
@@ -126,46 +126,66 @@ def init_embeddings(
|
|
|
126
126
|
provider: str | None = None,
|
|
127
127
|
**kwargs: Any,
|
|
128
128
|
) -> Embeddings:
|
|
129
|
-
"""Initialize an
|
|
129
|
+
"""Initialize an embedding model from a model name and optional provider.
|
|
130
|
+
|
|
131
|
+
!!! note
|
|
132
|
+
Requires the integration package for the chosen model provider to be installed.
|
|
133
|
+
|
|
134
|
+
See the `model_provider` parameter below for specific package names
|
|
135
|
+
(e.g., `pip install langchain-openai`).
|
|
130
136
|
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
Refer to the [provider integration's API reference](https://docs.langchain.com/oss/python/integrations/providers)
|
|
138
|
+
for supported model parameters to use as `**kwargs`.
|
|
133
139
|
|
|
134
140
|
Args:
|
|
135
|
-
model:
|
|
136
|
-
- A model string like "openai:text-embedding-3-small"
|
|
137
|
-
- Just the model name if provider is specified
|
|
138
|
-
provider: Optional explicit provider name. If not specified,
|
|
139
|
-
will attempt to parse from the model string. Supported providers
|
|
140
|
-
and their required packages:
|
|
141
|
+
model: The name of the model, e.g. `'openai:text-embedding-3-small'`.
|
|
141
142
|
|
|
142
|
-
|
|
143
|
+
You can also specify model and model provider in a single argument using
|
|
144
|
+
`'{model_provider}:{model}'` format, e.g. `'openai:text-embedding-3-small'`.
|
|
145
|
+
provider: The model provider if not specified as part of the model arg
|
|
146
|
+
(see above).
|
|
147
|
+
|
|
148
|
+
Supported `provider` values and the corresponding integration package
|
|
149
|
+
are:
|
|
150
|
+
|
|
151
|
+
- `openai` -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
|
|
152
|
+
- `azure_openai` -> [`langchain-openai`](https://docs.langchain.com/oss/python/integrations/providers/openai)
|
|
153
|
+
- `bedrock` -> [`langchain-aws`](https://docs.langchain.com/oss/python/integrations/providers/aws)
|
|
154
|
+
- `cohere` -> [`langchain-cohere`](https://docs.langchain.com/oss/python/integrations/providers/cohere)
|
|
155
|
+
- `google_vertexai` -> [`langchain-google-vertexai`](https://docs.langchain.com/oss/python/integrations/providers/google)
|
|
156
|
+
- `huggingface` -> [`langchain-huggingface`](https://docs.langchain.com/oss/python/integrations/providers/huggingface)
|
|
157
|
+
- `mistraiai` -> [`langchain-mistralai`](https://docs.langchain.com/oss/python/integrations/providers/mistralai)
|
|
158
|
+
- `ollama` -> [`langchain-ollama`](https://docs.langchain.com/oss/python/integrations/providers/ollama)
|
|
143
159
|
|
|
144
160
|
**kwargs: Additional model-specific parameters passed to the embedding model.
|
|
145
|
-
|
|
161
|
+
|
|
162
|
+
These vary by provider. Refer to the specific model provider's
|
|
163
|
+
[integration reference](https://reference.langchain.com/python/integrations/)
|
|
164
|
+
for all available parameters.
|
|
146
165
|
|
|
147
166
|
Returns:
|
|
148
|
-
An Embeddings instance that can generate embeddings for text.
|
|
167
|
+
An `Embeddings` instance that can generate embeddings for text.
|
|
149
168
|
|
|
150
169
|
Raises:
|
|
151
170
|
ValueError: If the model provider is not supported or cannot be determined
|
|
152
171
|
ImportError: If the required provider package is not installed
|
|
153
172
|
|
|
154
|
-
|
|
155
|
-
:open:
|
|
173
|
+
???+ example
|
|
156
174
|
|
|
157
|
-
|
|
175
|
+
```python
|
|
176
|
+
# pip install langchain langchain-openai
|
|
158
177
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
178
|
+
# Using a model string
|
|
179
|
+
model = init_embeddings("openai:text-embedding-3-small")
|
|
180
|
+
model.embed_query("Hello, world!")
|
|
162
181
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
# Using explicit provider
|
|
183
|
+
model = init_embeddings(model="text-embedding-3-small", provider="openai")
|
|
184
|
+
model.embed_documents(["Hello, world!", "Goodbye, world!"])
|
|
166
185
|
|
|
167
|
-
|
|
168
|
-
|
|
186
|
+
# With additional parameters
|
|
187
|
+
model = init_embeddings("openai:text-embedding-3-small", api_key="sk-...")
|
|
188
|
+
```
|
|
169
189
|
|
|
170
190
|
!!! version-added "Added in version 0.3.9"
|
|
171
191
|
|
langchain/messages/__init__.py
CHANGED
|
@@ -1,29 +1,78 @@
|
|
|
1
|
-
"""Message types.
|
|
1
|
+
"""Message and message content types.
|
|
2
|
+
|
|
3
|
+
Includes message types for different roles (e.g., human, AI, system), as well as types
|
|
4
|
+
for message content blocks (e.g., text, image, audio) and tool calls.
|
|
5
|
+
|
|
6
|
+
!!! warning "Reference docs"
|
|
7
|
+
This page contains **reference documentation** for Messages. See
|
|
8
|
+
[the docs](https://docs.langchain.com/oss/python/langchain/messages) for conceptual
|
|
9
|
+
guides, tutorials, and examples on using Messages.
|
|
10
|
+
"""
|
|
2
11
|
|
|
3
12
|
from langchain_core.messages import (
|
|
4
13
|
AIMessage,
|
|
5
14
|
AIMessageChunk,
|
|
15
|
+
Annotation,
|
|
6
16
|
AnyMessage,
|
|
17
|
+
AudioContentBlock,
|
|
18
|
+
Citation,
|
|
19
|
+
ContentBlock,
|
|
20
|
+
DataContentBlock,
|
|
21
|
+
FileContentBlock,
|
|
7
22
|
HumanMessage,
|
|
23
|
+
ImageContentBlock,
|
|
24
|
+
InputTokenDetails,
|
|
8
25
|
InvalidToolCall,
|
|
9
26
|
MessageLikeRepresentation,
|
|
27
|
+
NonStandardAnnotation,
|
|
28
|
+
NonStandardContentBlock,
|
|
29
|
+
OutputTokenDetails,
|
|
30
|
+
PlainTextContentBlock,
|
|
31
|
+
ReasoningContentBlock,
|
|
32
|
+
RemoveMessage,
|
|
33
|
+
ServerToolCall,
|
|
34
|
+
ServerToolCallChunk,
|
|
35
|
+
ServerToolResult,
|
|
10
36
|
SystemMessage,
|
|
37
|
+
TextContentBlock,
|
|
11
38
|
ToolCall,
|
|
12
39
|
ToolCallChunk,
|
|
13
40
|
ToolMessage,
|
|
41
|
+
UsageMetadata,
|
|
42
|
+
VideoContentBlock,
|
|
14
43
|
trim_messages,
|
|
15
44
|
)
|
|
16
45
|
|
|
17
46
|
__all__ = [
|
|
18
47
|
"AIMessage",
|
|
19
48
|
"AIMessageChunk",
|
|
49
|
+
"Annotation",
|
|
20
50
|
"AnyMessage",
|
|
51
|
+
"AudioContentBlock",
|
|
52
|
+
"Citation",
|
|
53
|
+
"ContentBlock",
|
|
54
|
+
"DataContentBlock",
|
|
55
|
+
"FileContentBlock",
|
|
21
56
|
"HumanMessage",
|
|
57
|
+
"ImageContentBlock",
|
|
58
|
+
"InputTokenDetails",
|
|
22
59
|
"InvalidToolCall",
|
|
23
60
|
"MessageLikeRepresentation",
|
|
61
|
+
"NonStandardAnnotation",
|
|
62
|
+
"NonStandardContentBlock",
|
|
63
|
+
"OutputTokenDetails",
|
|
64
|
+
"PlainTextContentBlock",
|
|
65
|
+
"ReasoningContentBlock",
|
|
66
|
+
"RemoveMessage",
|
|
67
|
+
"ServerToolCall",
|
|
68
|
+
"ServerToolCallChunk",
|
|
69
|
+
"ServerToolResult",
|
|
24
70
|
"SystemMessage",
|
|
71
|
+
"TextContentBlock",
|
|
25
72
|
"ToolCall",
|
|
26
73
|
"ToolCallChunk",
|
|
27
74
|
"ToolMessage",
|
|
75
|
+
"UsageMetadata",
|
|
76
|
+
"VideoContentBlock",
|
|
28
77
|
"trim_messages",
|
|
29
78
|
]
|
langchain/tools/__init__.py
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
"""Tools.
|
|
1
|
+
"""Tools.
|
|
2
|
+
|
|
3
|
+
!!! warning "Reference docs"
|
|
4
|
+
This page contains **reference documentation** for Tools. See
|
|
5
|
+
[the docs](https://docs.langchain.com/oss/python/langchain/tools) for conceptual
|
|
6
|
+
guides, tutorials, and examples on using Tools.
|
|
7
|
+
"""
|
|
2
8
|
|
|
3
9
|
from langchain_core.tools import (
|
|
4
10
|
BaseTool,
|
|
@@ -8,11 +14,7 @@ from langchain_core.tools import (
|
|
|
8
14
|
tool,
|
|
9
15
|
)
|
|
10
16
|
|
|
11
|
-
from langchain.tools.tool_node import
|
|
12
|
-
InjectedState,
|
|
13
|
-
InjectedStore,
|
|
14
|
-
ToolNode,
|
|
15
|
-
)
|
|
17
|
+
from langchain.tools.tool_node import InjectedState, InjectedStore, ToolRuntime
|
|
16
18
|
|
|
17
19
|
__all__ = [
|
|
18
20
|
"BaseTool",
|
|
@@ -21,6 +23,6 @@ __all__ = [
|
|
|
21
23
|
"InjectedToolArg",
|
|
22
24
|
"InjectedToolCallId",
|
|
23
25
|
"ToolException",
|
|
24
|
-
"
|
|
26
|
+
"ToolRuntime",
|
|
25
27
|
"tool",
|
|
26
28
|
]
|