transformers-haystack 1.0.0__tar.gz → 1.1.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.
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/CHANGELOG.md +18 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/PKG-INFO +1 -1
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/generators/transformers/chat/chat_generator.py +2 -6
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/readers/transformers/extractive_reader.py +1 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_chat_generator.py +0 -127
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_extractive_reader.py +15 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/.gitignore +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/LICENSE.txt +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/README.md +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/pydoc/config_docusaurus.yml +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/pyproject.toml +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/common/py.typed +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/common/transformers/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/common/transformers/utils.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/classifiers/py.typed +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/classifiers/transformers/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/classifiers/transformers/zero_shot_document_classifier.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/extractors/py.typed +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/extractors/transformers/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/extractors/transformers/named_entity_extractor.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/generators/transformers/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/generators/transformers/chat/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/readers/py.typed +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/readers/transformers/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/routers/py.typed +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/routers/transformers/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/routers/transformers/text_router.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/src/haystack_integrations/components/routers/transformers/zero_shot_text_router.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/__init__.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/conftest.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_named_entity_extractor.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_text_router.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_utils.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_zero_shot_document_classifier.py +0 -0
- {transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_zero_shot_text_router.py +0 -0
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [integrations/transformers-v1.0.1] - 2026-09-23
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Serialize missing init params in `to_dict` (transformers, amazon_bedrock) (#3873)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [integrations/transformers-v1.0.0] - 2026-09-10
|
|
11
|
+
|
|
12
|
+
### 🐛 Bug Fixes
|
|
13
|
+
|
|
14
|
+
- Fix (transformers): fix linting errors in transformers integration (#3867)
|
|
15
|
+
|
|
16
|
+
### 🚜 Refactor
|
|
17
|
+
|
|
18
|
+
- [**breaking**] Transformers - lifecycle refactor (#3939)
|
|
19
|
+
|
|
20
|
+
|
|
3
21
|
## [integrations/transformers-v0.3.0] - 2026-08-24
|
|
4
22
|
|
|
5
23
|
### 🐛 Bug Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: transformers-haystack
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Haystack integration for transformers
|
|
5
5
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/transformers#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
@@ -24,7 +24,6 @@ from haystack.tools import (
|
|
|
24
24
|
flatten_tools_or_toolsets,
|
|
25
25
|
serialize_tools_or_toolset,
|
|
26
26
|
)
|
|
27
|
-
from haystack.tools.utils import warm_up_tools
|
|
28
27
|
from haystack.utils import ComponentDevice, Secret, deserialize_callable, serialize_callable
|
|
29
28
|
from haystack.utils.hf import convert_message_to_hf_format, deserialize_hf_model_kwargs, serialize_hf_model_kwargs
|
|
30
29
|
from huggingface_hub import model_info
|
|
@@ -238,7 +237,7 @@ class TransformersChatGenerator:
|
|
|
238
237
|
|
|
239
238
|
def warm_up(self) -> None:
|
|
240
239
|
"""
|
|
241
|
-
Initializes the
|
|
240
|
+
Initializes the Transformers pipeline and the executor owned by the component.
|
|
242
241
|
"""
|
|
243
242
|
if self.pipeline is None:
|
|
244
243
|
pipeline_kwargs = _with_hf_token(self.huggingface_pipeline_kwargs, self.token)
|
|
@@ -251,10 +250,7 @@ class TransformersChatGenerator:
|
|
|
251
250
|
raise ValueError(msg)
|
|
252
251
|
pipeline_kwargs["task"] = task
|
|
253
252
|
|
|
254
|
-
|
|
255
|
-
if self.tools:
|
|
256
|
-
warm_up_tools(self.tools)
|
|
257
|
-
self.pipeline = hf_pipeline
|
|
253
|
+
self.pipeline = pipeline(**pipeline_kwargs)
|
|
258
254
|
|
|
259
255
|
if self._owns_executor and self.executor is None:
|
|
260
256
|
self.executor = ThreadPoolExecutor(
|
|
@@ -365,133 +365,6 @@ class TestComponentLifecycle:
|
|
|
365
365
|
device="cpu",
|
|
366
366
|
)
|
|
367
367
|
|
|
368
|
-
@patch("haystack_integrations.components.generators.transformers.chat.chat_generator.pipeline")
|
|
369
|
-
def test_warm_up_with_tools(self, pipeline_mock):
|
|
370
|
-
"""Test that warm_up() calls warm_up on tools and is idempotent."""
|
|
371
|
-
|
|
372
|
-
# Create a mock tool that tracks if warm_up() was called
|
|
373
|
-
class MockTool(Tool):
|
|
374
|
-
warm_up_call_count = 0 # Class variable to track calls
|
|
375
|
-
|
|
376
|
-
def __init__(self):
|
|
377
|
-
super().__init__(
|
|
378
|
-
name="mock_tool",
|
|
379
|
-
description="A mock tool for testing",
|
|
380
|
-
parameters={"x": {"type": "string"}},
|
|
381
|
-
function=lambda x: x,
|
|
382
|
-
)
|
|
383
|
-
|
|
384
|
-
def warm_up(self):
|
|
385
|
-
MockTool.warm_up_call_count += 1
|
|
386
|
-
|
|
387
|
-
# Reset the class variable before test
|
|
388
|
-
MockTool.warm_up_call_count = 0
|
|
389
|
-
mock_tool = MockTool()
|
|
390
|
-
|
|
391
|
-
# Create TransformersChatGenerator with the mock tool
|
|
392
|
-
generator = TransformersChatGenerator(
|
|
393
|
-
model="mistralai/Mistral-7B-Instruct-v0.2",
|
|
394
|
-
task="text-generation",
|
|
395
|
-
device=ComponentDevice.from_str("cpu"),
|
|
396
|
-
tools=[mock_tool],
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
# Verify initial state - warm_up not called yet
|
|
400
|
-
assert MockTool.warm_up_call_count == 0
|
|
401
|
-
assert generator.pipeline is None
|
|
402
|
-
|
|
403
|
-
# Call warm_up() on the generator
|
|
404
|
-
generator.warm_up()
|
|
405
|
-
|
|
406
|
-
# Assert that the tool's warm_up() was called
|
|
407
|
-
assert MockTool.warm_up_call_count == 1
|
|
408
|
-
assert generator.pipeline is not None
|
|
409
|
-
|
|
410
|
-
# Verify pipeline was initialized
|
|
411
|
-
pipeline_mock.assert_called_once()
|
|
412
|
-
|
|
413
|
-
# Call warm_up() again and verify it's idempotent (only warms up once)
|
|
414
|
-
generator.warm_up()
|
|
415
|
-
|
|
416
|
-
# The tool's warm_up should still only have been called once
|
|
417
|
-
assert MockTool.warm_up_call_count == 1
|
|
418
|
-
assert generator.pipeline is not None
|
|
419
|
-
# Pipeline should still only have been called once
|
|
420
|
-
pipeline_mock.assert_called_once()
|
|
421
|
-
|
|
422
|
-
@patch("haystack_integrations.components.generators.transformers.chat.chat_generator.pipeline")
|
|
423
|
-
def test_warm_up_with_no_tools(self, pipeline_mock):
|
|
424
|
-
"""Test that warm_up() works when no tools are provided."""
|
|
425
|
-
|
|
426
|
-
generator = TransformersChatGenerator(
|
|
427
|
-
model="mistralai/Mistral-7B-Instruct-v0.2", task="text-generation", device=ComponentDevice.from_str("cpu")
|
|
428
|
-
)
|
|
429
|
-
|
|
430
|
-
# Verify initial state
|
|
431
|
-
assert generator.pipeline is None
|
|
432
|
-
assert generator.tools is None
|
|
433
|
-
|
|
434
|
-
# Call warm_up() - should not raise an error
|
|
435
|
-
generator.warm_up()
|
|
436
|
-
|
|
437
|
-
# Verify the component is warmed up
|
|
438
|
-
assert generator.pipeline is not None
|
|
439
|
-
pipeline_mock.assert_called_once()
|
|
440
|
-
|
|
441
|
-
# Call warm_up() again - should be idempotent
|
|
442
|
-
generator.warm_up()
|
|
443
|
-
assert generator.pipeline is not None
|
|
444
|
-
# Pipeline should still only have been called once
|
|
445
|
-
pipeline_mock.assert_called_once()
|
|
446
|
-
|
|
447
|
-
@patch("haystack_integrations.components.generators.transformers.chat.chat_generator.pipeline")
|
|
448
|
-
def test_warm_up_with_multiple_tools(self, pipeline_mock):
|
|
449
|
-
"""Test that warm_up() works with multiple tools."""
|
|
450
|
-
|
|
451
|
-
# Track warm_up calls
|
|
452
|
-
warm_up_calls = []
|
|
453
|
-
|
|
454
|
-
class MockTool(Tool):
|
|
455
|
-
def __init__(self, tool_name):
|
|
456
|
-
super().__init__(
|
|
457
|
-
name=tool_name,
|
|
458
|
-
description=f"Mock tool {tool_name}",
|
|
459
|
-
parameters={"type": "object", "properties": {"x": {"type": "string"}}, "required": ["x"]},
|
|
460
|
-
function=lambda x: f"{tool_name} result: {x}",
|
|
461
|
-
)
|
|
462
|
-
|
|
463
|
-
def warm_up(self):
|
|
464
|
-
warm_up_calls.append(self.name)
|
|
465
|
-
|
|
466
|
-
mock_tool1 = MockTool("tool1")
|
|
467
|
-
mock_tool2 = MockTool("tool2")
|
|
468
|
-
|
|
469
|
-
# Use a LIST of tools, not a Toolset
|
|
470
|
-
generator = TransformersChatGenerator(
|
|
471
|
-
model="mistralai/Mistral-7B-Instruct-v0.2",
|
|
472
|
-
task="text-generation",
|
|
473
|
-
device=ComponentDevice.from_str("cpu"),
|
|
474
|
-
tools=[mock_tool1, mock_tool2],
|
|
475
|
-
)
|
|
476
|
-
|
|
477
|
-
# Call warm_up()
|
|
478
|
-
generator.warm_up()
|
|
479
|
-
|
|
480
|
-
# Assert that both tools' warm_up() were called
|
|
481
|
-
assert "tool1" in warm_up_calls
|
|
482
|
-
assert "tool2" in warm_up_calls
|
|
483
|
-
assert generator.pipeline is not None
|
|
484
|
-
pipeline_mock.assert_called_once()
|
|
485
|
-
|
|
486
|
-
# Track count
|
|
487
|
-
call_count = len(warm_up_calls)
|
|
488
|
-
|
|
489
|
-
# Verify idempotency
|
|
490
|
-
generator.warm_up()
|
|
491
|
-
assert len(warm_up_calls) == call_count
|
|
492
|
-
# Pipeline should still only have been called once
|
|
493
|
-
pipeline_mock.assert_called_once()
|
|
494
|
-
|
|
495
368
|
|
|
496
369
|
class TestRun:
|
|
497
370
|
def test_run(self, mock_pipeline_with_tokenizer, chat_messages):
|
|
@@ -150,6 +150,7 @@ def test_to_dict(initialized_token: Secret):
|
|
|
150
150
|
"answers_per_seq": None,
|
|
151
151
|
"no_answer": True,
|
|
152
152
|
"calibration_factor": 0.1,
|
|
153
|
+
"overlap_threshold": 0.01,
|
|
153
154
|
"model_kwargs": {
|
|
154
155
|
"torch_dtype": "torch.float16",
|
|
155
156
|
"device_map": ComponentDevice.resolve_device(None).to_hf(),
|
|
@@ -158,6 +159,15 @@ def test_to_dict(initialized_token: Secret):
|
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
|
|
162
|
+
def test_overlap_threshold_survives_a_serialization_round_trip():
|
|
163
|
+
"""overlap_threshold decides which overlapping answers are deduplicated away in run()."""
|
|
164
|
+
reader = TransformersExtractiveReader("my-model", token=None, overlap_threshold=0.5)
|
|
165
|
+
|
|
166
|
+
restored = TransformersExtractiveReader.from_dict(reader.to_dict())
|
|
167
|
+
|
|
168
|
+
assert restored.overlap_threshold == 0.5
|
|
169
|
+
|
|
170
|
+
|
|
161
171
|
def test_to_dict_no_token():
|
|
162
172
|
component = TransformersExtractiveReader("my-model", token=None, model_kwargs={"torch_dtype": torch.float16})
|
|
163
173
|
data = component.to_dict()
|
|
@@ -178,6 +188,7 @@ def test_to_dict_no_token():
|
|
|
178
188
|
"answers_per_seq": None,
|
|
179
189
|
"no_answer": True,
|
|
180
190
|
"calibration_factor": 0.1,
|
|
191
|
+
"overlap_threshold": 0.01,
|
|
181
192
|
"model_kwargs": {
|
|
182
193
|
"torch_dtype": "torch.float16",
|
|
183
194
|
"device_map": ComponentDevice.resolve_device(None).to_hf(),
|
|
@@ -206,6 +217,7 @@ def test_to_dict_empty_model_kwargs(initialized_token: Secret):
|
|
|
206
217
|
"answers_per_seq": None,
|
|
207
218
|
"no_answer": True,
|
|
208
219
|
"calibration_factor": 0.1,
|
|
220
|
+
"overlap_threshold": 0.01,
|
|
209
221
|
"model_kwargs": {"device_map": ComponentDevice.resolve_device(None).to_hf()},
|
|
210
222
|
},
|
|
211
223
|
}
|
|
@@ -239,6 +251,7 @@ def test_to_dict_device_map(device_map, expected):
|
|
|
239
251
|
"answers_per_seq": None,
|
|
240
252
|
"no_answer": True,
|
|
241
253
|
"calibration_factor": 0.1,
|
|
254
|
+
"overlap_threshold": 0.01,
|
|
242
255
|
"model_kwargs": {"device_map": expected},
|
|
243
256
|
},
|
|
244
257
|
}
|
|
@@ -261,6 +274,7 @@ def test_from_dict():
|
|
|
261
274
|
"answers_per_seq": None,
|
|
262
275
|
"no_answer": True,
|
|
263
276
|
"calibration_factor": 0.1,
|
|
277
|
+
"overlap_threshold": 0.01,
|
|
264
278
|
"model_kwargs": {"torch_dtype": "torch.float16"},
|
|
265
279
|
},
|
|
266
280
|
}
|
|
@@ -325,6 +339,7 @@ def test_from_dict_no_token():
|
|
|
325
339
|
"answers_per_seq": None,
|
|
326
340
|
"no_answer": True,
|
|
327
341
|
"calibration_factor": 0.1,
|
|
342
|
+
"overlap_threshold": 0.01,
|
|
328
343
|
"model_kwargs": {"torch_dtype": "torch.float16"},
|
|
329
344
|
},
|
|
330
345
|
}
|
|
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
|
|
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
|
{transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_named_entity_extractor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{transformers_haystack-1.0.0 → transformers_haystack-1.1.0}/tests/test_zero_shot_text_router.py
RENAMED
|
File without changes
|