huggingface-api-haystack 0.3.0__tar.gz → 0.4.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.
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/CHANGELOG.md +15 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/PKG-INFO +1 -1
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/generators/huggingface_api/chat/chat_generator.py +6 -3
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/conftest.py +10 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_chat_generator.py +13 -52
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/.gitignore +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/LICENSE.txt +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/README.md +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/pydoc/config_docusaurus.yml +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/pyproject.toml +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/common/huggingface_api/__init__.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/common/huggingface_api/utils.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/common/py.typed +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/embedders/huggingface_api/__init__.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/embedders/huggingface_api/document_embedder.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/embedders/huggingface_api/text_embedder.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/generators/huggingface_api/__init__.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/generators/huggingface_api/chat/__init__.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/rankers/huggingface_api/__init__.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/rankers/huggingface_api/ranker.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/src/haystack_integrations/components/rankers/py.typed +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/__init__.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_document_embedder.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_files/apple.jpg +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_ranker.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_text_embedder.py +0 -0
- {huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_utils.py +0 -0
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [integrations/huggingface_api-v0.3.0] - 2026-06-26
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Validate top_k in HuggingFaceTEIRanker (#3503)
|
|
8
|
+
|
|
9
|
+
### 🧪 Testing
|
|
10
|
+
|
|
11
|
+
- Improve del_hf_env_vars fixture (#3428)
|
|
12
|
+
|
|
13
|
+
### 🧹 Chores
|
|
14
|
+
|
|
15
|
+
- Improve consistency of integrations folder structure (#3430)
|
|
16
|
+
|
|
17
|
+
|
|
3
18
|
## [integrations/huggingface_api-v0.2.0] - 2026-06-05
|
|
4
19
|
|
|
5
20
|
### 🚀 Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: huggingface-api-haystack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Haystack integration for Hugging Face API
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/huggingface_api#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
|
|
5
|
+
import inspect
|
|
5
6
|
import json
|
|
6
7
|
from collections.abc import AsyncIterable, Iterable
|
|
7
8
|
from datetime import datetime, timezone
|
|
@@ -10,7 +11,6 @@ from typing import Any, Union
|
|
|
10
11
|
from haystack import component, default_from_dict, default_to_dict, logging
|
|
11
12
|
from haystack.components.generators.utils import _convert_streaming_chunks_to_chat_message, _normalize_messages
|
|
12
13
|
from haystack.dataclasses import (
|
|
13
|
-
AsyncStreamingCallbackT,
|
|
14
14
|
ChatMessage,
|
|
15
15
|
ComponentInfo,
|
|
16
16
|
ReasoningContent,
|
|
@@ -680,7 +680,7 @@ class HuggingFaceAPIChatGenerator:
|
|
|
680
680
|
self,
|
|
681
681
|
messages: list[dict[str, str]],
|
|
682
682
|
generation_kwargs: dict[str, Any],
|
|
683
|
-
streaming_callback:
|
|
683
|
+
streaming_callback: StreamingCallbackT,
|
|
684
684
|
) -> dict[str, list[ChatMessage]]:
|
|
685
685
|
api_output: AsyncIterable[ChatCompletionStreamOutput] = await self._async_client.chat_completion(
|
|
686
686
|
messages,
|
|
@@ -696,7 +696,10 @@ class HuggingFaceAPIChatGenerator:
|
|
|
696
696
|
chunk=chunk, previous_chunks=streaming_chunks, component_info=component_info
|
|
697
697
|
)
|
|
698
698
|
streaming_chunks.append(stream_chunk)
|
|
699
|
-
await
|
|
699
|
+
# sync callbacks are allowed in async contexts with Haystack >= 3.0, so only await async ones
|
|
700
|
+
callback_result = streaming_callback(stream_chunk)
|
|
701
|
+
if inspect.isawaitable(callback_result):
|
|
702
|
+
await callback_result
|
|
700
703
|
|
|
701
704
|
message = _convert_streaming_chunks_to_chat_message(chunks=streaming_chunks)
|
|
702
705
|
if message.meta.get("usage") is None:
|
|
@@ -27,3 +27,13 @@ def del_hf_env_vars_if_empty(monkeypatch):
|
|
|
27
27
|
for var in ("HF_API_TOKEN", "HF_TOKEN"):
|
|
28
28
|
if not os.environ.get(var, "").strip():
|
|
29
29
|
monkeypatch.delenv(var, raising=False)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.fixture(autouse=True)
|
|
33
|
+
def allow_deserialization_of_test_modules(monkeypatch):
|
|
34
|
+
"""
|
|
35
|
+
haystack-ai >= 3.0 refuses to deserialize classes and callables from modules outside its
|
|
36
|
+
trusted-module allowlist. Tools and callbacks defined in the test modules live outside that
|
|
37
|
+
allowlist, so trust them explicitly; haystack-ai 2.x ignores this environment variable.
|
|
38
|
+
"""
|
|
39
|
+
monkeypatch.setenv("HAYSTACK_DESERIALIZATION_ALLOWLIST", "tests,test_*")
|
{huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_chat_generator.py
RENAMED
|
@@ -270,20 +270,10 @@ class TestHuggingFaceAPIChatGenerator:
|
|
|
270
270
|
assert init_params["token"] == {"env_vars": ["HF_API_TOKEN", "HF_TOKEN"], "strict": False, "type": "env_var"}
|
|
271
271
|
assert init_params["generation_kwargs"] == {"temperature": 0.6, "stop": ["stop", "words"], "max_tokens": 512}
|
|
272
272
|
assert init_params["streaming_callback"] is None
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
"description": "description",
|
|
278
|
-
"function": "builtins.print",
|
|
279
|
-
"inputs_from_state": None,
|
|
280
|
-
"name": "name",
|
|
281
|
-
"outputs_to_state": None,
|
|
282
|
-
"outputs_to_string": None,
|
|
283
|
-
"parameters": {"x": {"type": "string"}},
|
|
284
|
-
},
|
|
285
|
-
}
|
|
286
|
-
]
|
|
273
|
+
|
|
274
|
+
# deserializing the serialized component must reproduce the original tool
|
|
275
|
+
loaded = HuggingFaceAPIChatGenerator.from_dict(result)
|
|
276
|
+
assert loaded.tools == [tool]
|
|
287
277
|
|
|
288
278
|
def test_from_dict(self, mock_check_valid_model):
|
|
289
279
|
tool = Tool(name="name", description="description", parameters={"x": {"type": "string"}}, function=print)
|
|
@@ -323,6 +313,11 @@ class TestHuggingFaceAPIChatGenerator:
|
|
|
323
313
|
pipeline.add_component("generator", generator)
|
|
324
314
|
|
|
325
315
|
pipeline_dict = pipeline.to_dict()
|
|
316
|
+
|
|
317
|
+
# the Tool serialization format is owned by haystack-ai and varies across its versions; the
|
|
318
|
+
# dumps/loads round-trip below covers the tools, so exclude them from the pinned-dict comparison
|
|
319
|
+
tools_entries = pipeline_dict["components"]["generator"]["init_parameters"].pop("tools")
|
|
320
|
+
assert len(tools_entries) == 1
|
|
326
321
|
assert pipeline_dict == {
|
|
327
322
|
"metadata": {},
|
|
328
323
|
"max_runs_per_component": 100,
|
|
@@ -337,20 +332,6 @@ class TestHuggingFaceAPIChatGenerator:
|
|
|
337
332
|
"token": {"type": "env_var", "env_vars": ["ENV_VAR"], "strict": False},
|
|
338
333
|
"generation_kwargs": {"temperature": 0.6, "stop": ["stop", "words"], "max_tokens": 512},
|
|
339
334
|
"streaming_callback": None,
|
|
340
|
-
"tools": [
|
|
341
|
-
{
|
|
342
|
-
"type": "haystack.tools.tool.Tool",
|
|
343
|
-
"data": {
|
|
344
|
-
"inputs_from_state": None,
|
|
345
|
-
"name": "name",
|
|
346
|
-
"outputs_to_state": None,
|
|
347
|
-
"outputs_to_string": None,
|
|
348
|
-
"description": "description",
|
|
349
|
-
"parameters": {"x": {"type": "string"}},
|
|
350
|
-
"function": "builtins.print",
|
|
351
|
-
},
|
|
352
|
-
}
|
|
353
|
-
],
|
|
354
335
|
},
|
|
355
336
|
}
|
|
356
337
|
},
|
|
@@ -1189,30 +1170,10 @@ class TestHuggingFaceAPIChatGenerator:
|
|
|
1189
1170
|
)
|
|
1190
1171
|
data = generator.to_dict()
|
|
1191
1172
|
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
{
|
|
1197
|
-
"type": "haystack.tools.tool.Tool",
|
|
1198
|
-
"data": {
|
|
1199
|
-
"name": "weather",
|
|
1200
|
-
"description": "useful to determine the weather in a given location",
|
|
1201
|
-
"parameters": {
|
|
1202
|
-
"type": "object",
|
|
1203
|
-
"properties": {"city": {"type": "string"}},
|
|
1204
|
-
"required": ["city"],
|
|
1205
|
-
},
|
|
1206
|
-
"function": "tests.test_chat_generator.get_weather",
|
|
1207
|
-
"outputs_to_string": None,
|
|
1208
|
-
"inputs_from_state": None,
|
|
1209
|
-
"outputs_to_state": None,
|
|
1210
|
-
},
|
|
1211
|
-
}
|
|
1212
|
-
]
|
|
1213
|
-
},
|
|
1214
|
-
}
|
|
1215
|
-
assert data["init_parameters"]["tools"] == expected_tools_data
|
|
1173
|
+
# deserializing the serialized component must reproduce the original toolset
|
|
1174
|
+
loaded = HuggingFaceAPIChatGenerator.from_dict(data)
|
|
1175
|
+
assert isinstance(loaded.tools, Toolset)
|
|
1176
|
+
assert list(loaded.tools) == list(toolset)
|
|
1216
1177
|
|
|
1217
1178
|
def test_convert_tools_to_hfapi_tools(self):
|
|
1218
1179
|
assert _convert_tools_to_hfapi_tools(None) is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/pydoc/config_docusaurus.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_document_embedder.py
RENAMED
|
File without changes
|
{huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_files/apple.jpg
RENAMED
|
File without changes
|
|
File without changes
|
{huggingface_api_haystack-0.3.0 → huggingface_api_haystack-0.4.0}/tests/test_text_embedder.py
RENAMED
|
File without changes
|
|
File without changes
|