amazon-bedrock-haystack 5.0.0__py3-none-any.whl → 5.2.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.
- {amazon_bedrock_haystack-5.0.0.dist-info → amazon_bedrock_haystack-5.2.0.dist-info}/METADATA +2 -2
- {amazon_bedrock_haystack-5.0.0.dist-info → amazon_bedrock_haystack-5.2.0.dist-info}/RECORD +6 -6
- haystack_integrations/components/downloaders/s3/s3_downloader.py +24 -3
- haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py +20 -18
- {amazon_bedrock_haystack-5.0.0.dist-info → amazon_bedrock_haystack-5.2.0.dist-info}/WHEEL +0 -0
- {amazon_bedrock_haystack-5.0.0.dist-info → amazon_bedrock_haystack-5.2.0.dist-info}/licenses/LICENSE.txt +0 -0
{amazon_bedrock_haystack-5.0.0.dist-info → amazon_bedrock_haystack-5.2.0.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: amazon-bedrock-haystack
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.2.0
|
|
4
4
|
Summary: An integration of AWS S3 and Bedrock as a Downloader and Generator components.
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/amazon_bedrock#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -21,7 +21,7 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
|
21
21
|
Requires-Python: >=3.9
|
|
22
22
|
Requires-Dist: aioboto3>=14.0.0
|
|
23
23
|
Requires-Dist: boto3>=1.28.57
|
|
24
|
-
Requires-Dist: haystack-ai>=2.
|
|
24
|
+
Requires-Dist: haystack-ai>=2.19.0
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
26
26
|
|
|
27
27
|
# amazon-bedrock-haystack
|
|
@@ -7,7 +7,7 @@ haystack_integrations/common/s3/errors.py,sha256=BrTDLdhQvAuQutyg35cFyP5h8PNkDEi
|
|
|
7
7
|
haystack_integrations/common/s3/utils.py,sha256=OJupFj54aQmg6S8VuVq6Lc2qpFZyyJajRVIpwe3_6iA,4744
|
|
8
8
|
haystack_integrations/components/downloaders/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
haystack_integrations/components/downloaders/s3/__init__.py,sha256=2BOd3_N0kGqRJGH-ENrTJqOqzqHryRYaSuNqpLYKMFo,179
|
|
10
|
-
haystack_integrations/components/downloaders/s3/s3_downloader.py,sha256=
|
|
10
|
+
haystack_integrations/components/downloaders/s3/s3_downloader.py,sha256=qarIeGxwDCA1BOZ1qdLfE8NcQtMS9bW54a8voEBHTbE,12637
|
|
11
11
|
haystack_integrations/components/embedders/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
haystack_integrations/components/embedders/amazon_bedrock/__init__.py,sha256=7GlhHJ4jFHCxq5QN5losGuGtrGNjvEx2dSQvEYD2yG0,408
|
|
13
13
|
haystack_integrations/components/embedders/amazon_bedrock/document_embedder.py,sha256=DD34-HAGwGwTU7KWGqKXXlFdwIs21JavBRDHrBqC-m4,13060
|
|
@@ -18,12 +18,12 @@ haystack_integrations/components/generators/amazon_bedrock/__init__.py,sha256=lv
|
|
|
18
18
|
haystack_integrations/components/generators/amazon_bedrock/adapters.py,sha256=yBC-3YwV6qAwSXMtdZiLSYh2lUpPQIDy7Efl7w-Cu-k,19640
|
|
19
19
|
haystack_integrations/components/generators/amazon_bedrock/generator.py,sha256=Brzw0XvtPJhz2kR2I3liAqWHRmDR6p5HzJerEAPhoJU,14743
|
|
20
20
|
haystack_integrations/components/generators/amazon_bedrock/chat/__init__.py,sha256=6GZ8Y3Lw0rLOsOAqi6Tu5mZC977UzQvgDxKpOWr8IQw,110
|
|
21
|
-
haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py,sha256=
|
|
21
|
+
haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py,sha256=fwjNUrQM4UziGBVZKvsVEZVcKPF00ZY7CY0g2Advwxs,26246
|
|
22
22
|
haystack_integrations/components/generators/amazon_bedrock/chat/utils.py,sha256=1M_k8CG2WH23Yz-sB7a1kiIqVh2QB8Pqi0zbWXyMUL8,27255
|
|
23
23
|
haystack_integrations/components/rankers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
haystack_integrations/components/rankers/amazon_bedrock/__init__.py,sha256=mJQKShAP5AfZvfKQisSh7kfKu6RIXzsYdk4eqMtcaEk,75
|
|
25
25
|
haystack_integrations/components/rankers/amazon_bedrock/ranker.py,sha256=QWtUKfJxMrlfLCWTb8cCP-lKEthnEBwnTd1NSbiFMkg,11812
|
|
26
|
-
amazon_bedrock_haystack-5.
|
|
27
|
-
amazon_bedrock_haystack-5.
|
|
28
|
-
amazon_bedrock_haystack-5.
|
|
29
|
-
amazon_bedrock_haystack-5.
|
|
26
|
+
amazon_bedrock_haystack-5.2.0.dist-info/METADATA,sha256=DO5DjQps1pXcLOiyLmzvoRnf4xgMKE0kYSSFPiFfQeo,2228
|
|
27
|
+
amazon_bedrock_haystack-5.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
28
|
+
amazon_bedrock_haystack-5.2.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
|
|
29
|
+
amazon_bedrock_haystack-5.2.0.dist-info/RECORD,,
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
import os
|
|
6
6
|
from concurrent.futures import ThreadPoolExecutor
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from typing import Any, Dict, List, Optional
|
|
8
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
9
9
|
|
|
10
10
|
from botocore.config import Config
|
|
11
11
|
from haystack import component, default_from_dict, default_to_dict, logging
|
|
12
12
|
from haystack.dataclasses import Document
|
|
13
13
|
from haystack.utils.auth import Secret, deserialize_secrets_inplace
|
|
14
|
+
from haystack.utils.callable_serialization import deserialize_callable, serialize_callable
|
|
14
15
|
|
|
15
16
|
from haystack_integrations.common.amazon_bedrock.utils import get_aws_session
|
|
16
17
|
from haystack_integrations.common.s3.utils import S3Storage
|
|
@@ -41,6 +42,7 @@ class S3Downloader:
|
|
|
41
42
|
file_name_meta_key: str = "file_name",
|
|
42
43
|
max_workers: int = 32,
|
|
43
44
|
max_cache_size: int = 100,
|
|
45
|
+
s3_key_generation_function: Optional[Callable[[Document], str]] = None,
|
|
44
46
|
) -> None:
|
|
45
47
|
"""
|
|
46
48
|
Initializes the `S3Downloader` with the provided parameters.
|
|
@@ -64,9 +66,15 @@ class S3Downloader:
|
|
|
64
66
|
By default, all file extensions are allowed.
|
|
65
67
|
:param max_workers: The maximum number of workers to use for concurrent downloads.
|
|
66
68
|
:param max_cache_size: The maximum number of files to cache.
|
|
67
|
-
:param file_name_meta_key: The name of the meta key that contains the file name to download.
|
|
69
|
+
:param file_name_meta_key: The name of the meta key that contains the file name to download. The file name
|
|
70
|
+
will also be used to create local file path for download.
|
|
68
71
|
By default, the `Document.meta["file_name"]` is used. If you want to use a
|
|
69
72
|
different key in `Document.meta`, you can set it here.
|
|
73
|
+
:param s3_key_generation_function: An optional function that generates the S3 key for the file to download.
|
|
74
|
+
If not provided, the default behavior is to use `Document.meta[file_name_meta_key]`.
|
|
75
|
+
The function must accept a `Document` object and return a string.
|
|
76
|
+
If the environment variable `S3_DOWNLOADER_PREFIX` is set, its value will be automatically
|
|
77
|
+
prefixed to the generated S3 key.
|
|
70
78
|
:raises ValueError: If the `file_root_path` is not set through
|
|
71
79
|
the constructor or the `FILE_ROOT_PATH` environment variable.
|
|
72
80
|
|
|
@@ -94,6 +102,7 @@ class S3Downloader:
|
|
|
94
102
|
self.max_workers = max_workers
|
|
95
103
|
self.max_cache_size = max_cache_size
|
|
96
104
|
self.file_name_meta_key = file_name_meta_key
|
|
105
|
+
self.s3_key_generation_function = s3_key_generation_function
|
|
97
106
|
|
|
98
107
|
self._storage: Optional[S3Storage] = None
|
|
99
108
|
|
|
@@ -186,8 +195,9 @@ class S3Downloader:
|
|
|
186
195
|
file_path.touch()
|
|
187
196
|
|
|
188
197
|
else:
|
|
198
|
+
s3_key = self.s3_key_generation_function(document) if self.s3_key_generation_function else file_name
|
|
189
199
|
# we know that _storage is not None after warm_up() is called, but mypy does not know that
|
|
190
|
-
self._storage.download(key=
|
|
200
|
+
self._storage.download(key=s3_key, local_file_path=file_path) # type: ignore[union-attr]
|
|
191
201
|
|
|
192
202
|
document.meta["file_path"] = str(file_path)
|
|
193
203
|
return document
|
|
@@ -216,6 +226,11 @@ class S3Downloader:
|
|
|
216
226
|
|
|
217
227
|
def to_dict(self) -> Dict[str, Any]:
|
|
218
228
|
"""Serialize the component to a dictionary."""
|
|
229
|
+
|
|
230
|
+
s3_key_generation_function_name = (
|
|
231
|
+
serialize_callable(self.s3_key_generation_function) if self.s3_key_generation_function else None
|
|
232
|
+
)
|
|
233
|
+
|
|
219
234
|
return default_to_dict(
|
|
220
235
|
self,
|
|
221
236
|
aws_access_key_id=self.aws_access_key_id.to_dict() if self.aws_access_key_id else None,
|
|
@@ -228,6 +243,7 @@ class S3Downloader:
|
|
|
228
243
|
max_cache_size=self.max_cache_size,
|
|
229
244
|
file_extensions=self.file_extensions,
|
|
230
245
|
file_name_meta_key=self.file_name_meta_key,
|
|
246
|
+
s3_key_generation_function=s3_key_generation_function_name,
|
|
231
247
|
)
|
|
232
248
|
|
|
233
249
|
@classmethod
|
|
@@ -239,6 +255,11 @@ class S3Downloader:
|
|
|
239
255
|
:returns:
|
|
240
256
|
Deserialized component.
|
|
241
257
|
"""
|
|
258
|
+
s3_key_generation_function_name = data["init_parameters"].get("s3_key_generation_function")
|
|
259
|
+
if s3_key_generation_function_name:
|
|
260
|
+
data["init_parameters"]["s3_key_generation_function"] = deserialize_callable(
|
|
261
|
+
s3_key_generation_function_name
|
|
262
|
+
)
|
|
242
263
|
deserialize_secrets_inplace(
|
|
243
264
|
data["init_parameters"],
|
|
244
265
|
["aws_access_key_id", "aws_secret_access_key", "aws_session_token", "aws_region_name", "aws_profile_name"],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any, Dict, List, Optional, Tuple
|
|
1
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
2
2
|
|
|
3
3
|
import aioboto3
|
|
4
4
|
from botocore.config import Config
|
|
@@ -7,10 +7,10 @@ from botocore.exceptions import ClientError
|
|
|
7
7
|
from haystack import component, default_from_dict, default_to_dict, logging
|
|
8
8
|
from haystack.dataclasses import ChatMessage, ComponentInfo, StreamingCallbackT, select_streaming_callback
|
|
9
9
|
from haystack.tools import (
|
|
10
|
-
|
|
11
|
-
Toolset,
|
|
10
|
+
ToolsType,
|
|
12
11
|
_check_duplicate_tool_names,
|
|
13
12
|
deserialize_tools_or_toolset_inplace,
|
|
13
|
+
flatten_tools_or_toolsets,
|
|
14
14
|
serialize_tools_or_toolset,
|
|
15
15
|
)
|
|
16
16
|
from haystack.utils.auth import Secret, deserialize_secrets_inplace
|
|
@@ -157,7 +157,7 @@ class AmazonBedrockChatGenerator:
|
|
|
157
157
|
generation_kwargs: Optional[Dict[str, Any]] = None,
|
|
158
158
|
streaming_callback: Optional[StreamingCallbackT] = None,
|
|
159
159
|
boto3_config: Optional[Dict[str, Any]] = None,
|
|
160
|
-
tools: Optional[
|
|
160
|
+
tools: Optional[ToolsType] = None,
|
|
161
161
|
*,
|
|
162
162
|
guardrail_config: Optional[Dict[str, str]] = None,
|
|
163
163
|
) -> None:
|
|
@@ -187,7 +187,8 @@ class AmazonBedrockChatGenerator:
|
|
|
187
187
|
[StreamingChunk](https://docs.haystack.deepset.ai/docs/data-classes#streamingchunk) object and switches
|
|
188
188
|
the streaming mode on.
|
|
189
189
|
:param boto3_config: The configuration for the boto3 client.
|
|
190
|
-
:param tools: A list of Tool objects or a Toolset
|
|
190
|
+
:param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
|
|
191
|
+
Each tool should have a unique name.
|
|
191
192
|
:param guardrail_config: Optional configuration for a guardrail that has been created in Amazon Bedrock.
|
|
192
193
|
This must be provided as a dictionary matching either
|
|
193
194
|
[GuardrailConfiguration](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GuardrailConfiguration.html).
|
|
@@ -218,7 +219,7 @@ class AmazonBedrockChatGenerator:
|
|
|
218
219
|
self.streaming_callback = streaming_callback
|
|
219
220
|
self.boto3_config = boto3_config
|
|
220
221
|
|
|
221
|
-
_check_duplicate_tool_names(
|
|
222
|
+
_check_duplicate_tool_names(flatten_tools_or_toolsets(tools))
|
|
222
223
|
self.tools = tools
|
|
223
224
|
|
|
224
225
|
_validate_guardrail_config(guardrail_config=guardrail_config, streaming=streaming_callback is not None)
|
|
@@ -342,7 +343,7 @@ class AmazonBedrockChatGenerator:
|
|
|
342
343
|
messages: List[ChatMessage],
|
|
343
344
|
streaming_callback: Optional[StreamingCallbackT] = None,
|
|
344
345
|
generation_kwargs: Optional[Dict[str, Any]] = None,
|
|
345
|
-
tools: Optional[
|
|
346
|
+
tools: Optional[ToolsType] = None,
|
|
346
347
|
requires_async: bool = False,
|
|
347
348
|
) -> Tuple[Dict[str, Any], Optional[StreamingCallbackT]]:
|
|
348
349
|
"""
|
|
@@ -358,7 +359,8 @@ class AmazonBedrockChatGenerator:
|
|
|
358
359
|
- `stopSequences`: List of stop sequences to stop generation.
|
|
359
360
|
- `temperature`: Sampling temperature.
|
|
360
361
|
- `topP`: Nucleus sampling parameter.
|
|
361
|
-
:param tools:
|
|
362
|
+
:param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
|
|
363
|
+
Each tool should have a unique name.
|
|
362
364
|
:param requires_async: Boolean flag to indicate if an async-compatible streaming callback function is needed.
|
|
363
365
|
|
|
364
366
|
:returns:
|
|
@@ -380,14 +382,12 @@ class AmazonBedrockChatGenerator:
|
|
|
380
382
|
|
|
381
383
|
# Handle tools - either toolConfig or Haystack Tool objects but not both
|
|
382
384
|
tools = tools or self.tools
|
|
383
|
-
|
|
385
|
+
flattened_tools = flatten_tools_or_toolsets(tools)
|
|
386
|
+
_check_duplicate_tool_names(flattened_tools)
|
|
384
387
|
tool_config = merged_kwargs.pop("toolConfig", None)
|
|
385
|
-
if
|
|
386
|
-
# Convert Toolset to list if needed
|
|
387
|
-
if isinstance(tools, Toolset):
|
|
388
|
-
tools = list(tools)
|
|
388
|
+
if flattened_tools:
|
|
389
389
|
# Format Haystack tools to Bedrock format
|
|
390
|
-
tool_config = _format_tools(
|
|
390
|
+
tool_config = _format_tools(flattened_tools)
|
|
391
391
|
|
|
392
392
|
# Any remaining kwargs go to additionalModelRequestFields
|
|
393
393
|
additional_fields = merged_kwargs if merged_kwargs else None
|
|
@@ -425,7 +425,7 @@ class AmazonBedrockChatGenerator:
|
|
|
425
425
|
messages: List[ChatMessage],
|
|
426
426
|
streaming_callback: Optional[StreamingCallbackT] = None,
|
|
427
427
|
generation_kwargs: Optional[Dict[str, Any]] = None,
|
|
428
|
-
tools: Optional[
|
|
428
|
+
tools: Optional[ToolsType] = None,
|
|
429
429
|
) -> Dict[str, List[ChatMessage]]:
|
|
430
430
|
"""
|
|
431
431
|
Executes a synchronous inference call to the Amazon Bedrock model using the Converse API.
|
|
@@ -439,7 +439,8 @@ class AmazonBedrockChatGenerator:
|
|
|
439
439
|
- `stopSequences`: List of stop sequences to stop generation.
|
|
440
440
|
- `temperature`: Sampling temperature.
|
|
441
441
|
- `topP`: Nucleus sampling parameter.
|
|
442
|
-
:param tools:
|
|
442
|
+
:param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
|
|
443
|
+
Each tool should have a unique name.
|
|
443
444
|
|
|
444
445
|
:returns:
|
|
445
446
|
A dictionary containing the model-generated replies under the `"replies"` key.
|
|
@@ -485,7 +486,7 @@ class AmazonBedrockChatGenerator:
|
|
|
485
486
|
messages: List[ChatMessage],
|
|
486
487
|
streaming_callback: Optional[StreamingCallbackT] = None,
|
|
487
488
|
generation_kwargs: Optional[Dict[str, Any]] = None,
|
|
488
|
-
tools: Optional[
|
|
489
|
+
tools: Optional[ToolsType] = None,
|
|
489
490
|
) -> Dict[str, List[ChatMessage]]:
|
|
490
491
|
"""
|
|
491
492
|
Executes an asynchronous inference call to the Amazon Bedrock model using the Converse API.
|
|
@@ -499,7 +500,8 @@ class AmazonBedrockChatGenerator:
|
|
|
499
500
|
- `stopSequences`: List of stop sequences to stop generation.
|
|
500
501
|
- `temperature`: Sampling temperature.
|
|
501
502
|
- `topP`: Nucleus sampling parameter.
|
|
502
|
-
:param tools:
|
|
503
|
+
:param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
|
|
504
|
+
Each tool should have a unique name.
|
|
503
505
|
|
|
504
506
|
:returns:
|
|
505
507
|
A dictionary containing the model-generated replies under the `"replies"` key.
|
|
File without changes
|
|
File without changes
|