mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-07-15 13:00:53 +00:00

* First rough implementation of refactored run * Further improve run logic * Properly handle variadic input in run * Further work * Enhance names and add more documentation * Fix issue with output distribution * This works * Enhance run comments * Mark Multiplexer as greedy * Remove MergeLoop in favour of Multiplexer in tests * Remove FirstIntSelector in favour of Multiplexer * Handle corner when waiting for input is stuck * Remove unused import * Handle mutable input data in run and misbehaving components * Handle run input validation * Test validation * Fix pylint * Fix mypy * Call warm_up in run to fix tests
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
from typing import List
|
|
|
|
from haystack.core.component import component
|
|
from haystack.core.pipeline import Pipeline
|
|
from haystack.testing.sample_components import StringListJoiner
|
|
|
|
|
|
@component
|
|
class InputMangler:
|
|
@component.output_types(mangled_list=List[str])
|
|
def run(self, input_list: List[str]):
|
|
input_list.append("extra_item")
|
|
return {"mangled_list": input_list}
|
|
|
|
|
|
def test_mutable_inputs():
|
|
pipe = Pipeline()
|
|
pipe.add_component("mangler1", InputMangler())
|
|
pipe.add_component("mangler2", InputMangler())
|
|
pipe.add_component("concat1", StringListJoiner())
|
|
pipe.add_component("concat2", StringListJoiner())
|
|
pipe.connect("mangler1", "concat1")
|
|
pipe.connect("mangler2", "concat2")
|
|
|
|
mylist = ["foo", "bar"]
|
|
|
|
result = pipe.run(data={"mangler1": {"input_list": mylist}, "mangler2": {"input_list": mylist}})
|
|
assert result["concat1"]["output"] == result["concat2"]["output"] == ["foo", "bar", "extra_item"]
|