anthropic-haystack 5.1.1__tar.gz → 5.2.0__tar.gz
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.
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/CHANGELOG.md +7 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/PKG-INFO +2 -2
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/pyproject.toml +2 -1
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/anthropic/chat/utils.py +38 -19
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/tests/test_chat_generator.py +55 -896
- anthropic_haystack-5.2.0/tests/test_utils.py +931 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/.gitignore +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/LICENSE.txt +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/README.md +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/example/documentation_rag_with_claude.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/example/prompt_caching.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/pydoc/config_docusaurus.yml +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/anthropic/__init__.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/anthropic/chat/__init__.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/anthropic/chat/vertex_chat_generator.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/anthropic/generator.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/tests/__init__.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/tests/conftest.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/tests/test_files/apple.jpg +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/tests/test_generator.py +0 -0
- {anthropic_haystack-5.1.1 → anthropic_haystack-5.2.0}/tests/test_vertex_chat_generator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: anthropic-haystack
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.2.0
|
|
4
4
|
Summary: An integration of Anthropic Claude models into the Haystack framework.
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/anthropic#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
|
19
19
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
20
|
Requires-Python: >=3.10
|
|
21
21
|
Requires-Dist: anthropic>=0.47.0
|
|
22
|
-
Requires-Dist: haystack-ai>=2.
|
|
22
|
+
Requires-Dist: haystack-ai>=2.23.0
|
|
23
23
|
Description-Content-Type: text/markdown
|
|
24
24
|
|
|
25
25
|
# anthropic-haystack
|
|
@@ -22,13 +22,14 @@ classifiers = [
|
|
|
22
22
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
23
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
24
|
]
|
|
25
|
-
dependencies = ["haystack-ai>=2.
|
|
25
|
+
dependencies = ["haystack-ai>=2.23.0", "anthropic>=0.47.0"]
|
|
26
26
|
|
|
27
27
|
[project.urls]
|
|
28
28
|
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/anthropic#readme"
|
|
29
29
|
Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues"
|
|
30
30
|
Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/anthropic"
|
|
31
31
|
|
|
32
|
+
|
|
32
33
|
[tool.hatch.build.targets.wheel]
|
|
33
34
|
packages = ["src/haystack_integrations"]
|
|
34
35
|
|
|
@@ -43,6 +43,28 @@ FINISH_REASON_MAPPING: dict[str, FinishReason] = {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
|
|
46
|
+
def _convert_image_content_to_anthropic_format(image_content: ImageContent) -> ImageBlockParam:
|
|
47
|
+
"""
|
|
48
|
+
Convert an ImageContent to the format expected by Anthropic Chat API.
|
|
49
|
+
"""
|
|
50
|
+
if image_content.mime_type not in IMAGE_SUPPORTED_FORMATS:
|
|
51
|
+
supported_formats = ", ".join(IMAGE_SUPPORTED_FORMATS)
|
|
52
|
+
msg = (
|
|
53
|
+
f"Unsupported image format: {image_content.mime_type}. "
|
|
54
|
+
f"Anthropic supports the following formats: {supported_formats}"
|
|
55
|
+
)
|
|
56
|
+
raise ValueError(msg)
|
|
57
|
+
|
|
58
|
+
return ImageBlockParam(
|
|
59
|
+
type="image",
|
|
60
|
+
source={
|
|
61
|
+
"type": "base64",
|
|
62
|
+
"media_type": cast(ImageFormat, image_content.mime_type),
|
|
63
|
+
"data": image_content.base64_image,
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
46
68
|
def _update_anthropic_message_with_tool_call_results(
|
|
47
69
|
tool_call_results: list[ToolCallResult],
|
|
48
70
|
content: list[
|
|
@@ -65,10 +87,22 @@ def _update_anthropic_message_with_tool_call_results(
|
|
|
65
87
|
msg = "`ToolCall` must have a non-null `id` attribute to be used with Anthropic."
|
|
66
88
|
raise ValueError(msg)
|
|
67
89
|
|
|
90
|
+
tool_result_block_content: list[TextBlockParam | ImageBlockParam] = []
|
|
91
|
+
if isinstance(tool_call_result.result, str):
|
|
92
|
+
tool_result_block_content.append(TextBlockParam(type="text", text=tool_call_result.result))
|
|
93
|
+
elif isinstance(tool_call_result.result, list):
|
|
94
|
+
for item in tool_call_result.result:
|
|
95
|
+
if isinstance(item, TextContent):
|
|
96
|
+
tool_result_block_content.append(TextBlockParam(type="text", text=item.text))
|
|
97
|
+
elif isinstance(item, ImageContent):
|
|
98
|
+
tool_result_block_content.append(_convert_image_content_to_anthropic_format(item))
|
|
99
|
+
else:
|
|
100
|
+
msg = "Unsupported content type in tool call result"
|
|
101
|
+
raise ValueError(msg)
|
|
68
102
|
tool_result_block = ToolResultBlockParam(
|
|
69
103
|
type="tool_result",
|
|
70
104
|
tool_use_id=tool_call_result.origin.id,
|
|
71
|
-
content=
|
|
105
|
+
content=tool_result_block_content,
|
|
72
106
|
is_error=tool_call_result.error,
|
|
73
107
|
)
|
|
74
108
|
content.append(tool_result_block)
|
|
@@ -162,26 +196,11 @@ def _convert_messages_to_anthropic_format(
|
|
|
162
196
|
content.append(reasoning_block)
|
|
163
197
|
|
|
164
198
|
elif isinstance(part, ImageContent):
|
|
165
|
-
if not message.is_from(ChatRole.USER):
|
|
166
|
-
msg = "Image content is only supported for user messages"
|
|
199
|
+
if not message.is_from(ChatRole.USER) and not message.is_from(ChatRole.TOOL):
|
|
200
|
+
msg = "Image content is only supported for user and tool messages"
|
|
167
201
|
raise ValueError(msg)
|
|
168
202
|
|
|
169
|
-
|
|
170
|
-
supported_formats = ", ".join(IMAGE_SUPPORTED_FORMATS)
|
|
171
|
-
msg = (
|
|
172
|
-
f"Unsupported image format: {part.mime_type}. "
|
|
173
|
-
f"Anthropic supports the following formats: {supported_formats}"
|
|
174
|
-
)
|
|
175
|
-
raise ValueError(msg)
|
|
176
|
-
|
|
177
|
-
image_block = ImageBlockParam(
|
|
178
|
-
type="image",
|
|
179
|
-
source={
|
|
180
|
-
"type": "base64",
|
|
181
|
-
"media_type": cast(ImageFormat, part.mime_type),
|
|
182
|
-
"data": part.base64_image,
|
|
183
|
-
},
|
|
184
|
-
)
|
|
203
|
+
image_block = _convert_image_content_to_anthropic_format(part)
|
|
185
204
|
if cache_control:
|
|
186
205
|
image_block["cache_control"] = cache_control
|
|
187
206
|
content.append(image_block)
|