MCPcopy Create free account
hub / github.com/apache/burr / HaystackAction

Class HaystackAction

burr/integrations/haystack.py:32–288  ·  view source on GitHub ↗

Burr ``Action`` wrapping a Haystack ``Component``. Haystack ``Component`` is the basic block of a Haystack ``Pipeline``. A ``Component`` is instantiated, then it receives inputs for its ``.run()`` method and returns output values. Learn more about components here: https://docs.hays

Source from the content-addressed store, hash-verified

30
31# TODO show OpenTelemetry integration
32class HaystackAction(Action):
33 """Burr ``Action`` wrapping a Haystack ``Component``.
34
35 Haystack ``Component`` is the basic block of a Haystack ``Pipeline``.
36 A ``Component`` is instantiated, then it receives inputs for its ``.run()`` method
37 and returns output values.
38
39 Learn more about components here: https://docs.haystack.deepset.ai/docs/custom-components
40 """
41
42 def __init__(
43 self,
44 component: Component,
45 reads: Union[list[str], dict[str, str]],
46 writes: Union[list[str], dict[str, str]],
47 name: Optional[str] = None,
48 bound_params: Optional[dict] = None,
49 do_warm_up: bool = True,
50 ):
51 """Create a Burr ``Action`` from a Haystack ``Component``.
52
53 :param component: Haystack ``Component`` to wrap
54 :param reads: State fields read and passed to ``Component.run()``.
55 Use a mapping {socket: state_field} to rename Haystack input sockets (see example).
56 :param writes: State fields where results of ``Component.run()`` are written.
57 Use a mapping {state_field: socket} to rename Haystack output sockets (see example).
58 :param name: Name of the action. Can be set later via ``.with_name()``
59 or in ``ApplicationBuilder.with_actions()``.
60 :param bound_params: Parameters to bind to the ``Component.run()`` method.
61 :param do_warm_up: If True, try to call ``Component.warm_up()`` if it exists.
62 If False, we assume ``.warm_up()`` was called before creating the ``HaystackAction``.
63 Read more about ``.warm_up()`` in the Haystack documentation: https://docs.haystack.deepset.ai/reference/pipeline-api#pipelinewarm_up
64
65 Pass the mapping ``{"foo": "state_field"}`` to read the value of ``state_field`` on the Burr state
66 and pass it to ``Component.run()`` as ``foo``.
67
68 .. code-block:: python
69
70 @component
71 class HaystackComponent:
72 @component.output_types()
73 def run(self, foo: int) -> dict:
74 return {}
75
76 HaystackAction(
77 component=HaystackComponent(),
78 reads={"foo": "state_field"},
79 writes=[]
80 )
81
82 Pass the mapping ``{"state_field": "bar"}`` to get the ``bar`` value from the results
83 of ``.run()`` and set the field ``state_field`` on the Burr state
84
85 .. code-block:: python
86
87 @component
88 class HaystackComponent:
89 @component.output_types(bar=int)

Calls

no outgoing calls