Set optional input parameter for custom component using component.set_input_types() #8989
Replies: 2 comments
-
Hi @danielescaramuzzi Haystack decides when to run a component in a pipeline based on whether the inputs it expects are available. That's why making an input optional can get complex. I suggest two options for what you want to achieve. For more context (from https://github.com/deepset-ai/haystack/blob/main/haystack/core/component/component.py#L384): For example: @component
class MyComponent:
def __init__(self, value: int):
component.set_input_types(self, value_1=str, value_2=str)
...
@component.output_types(output_1=int, output_2=str)
def run(self, value_0: str, value_1: Optional[str] = None, **kwargs):
return {"output_1": kwargs["value_1"], "output_2": ""} would add a mandatory |
Beta Was this translation helpful? Give feedback.
-
Hi @julian-risch,
Any insights on this would be appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
-
If I want to set inputs for a custom component in bulk using
component.set_input_types()
, I have no way to mark parameters as optional.Example (a component that receives a combination of
int
andOptional[int]
parameters)Using
Optional[int]
as type ofparam2
doesn't seem sufficient to make it optional. Looking at theset_input_types()
method in the component class,_empty
is used as default value for every input, making all inputs mandatory (it means that the component only runs when bothparam1
andparam2
are available).Is this behaviour expected?
If so, how can I make an input optional using
component.set_input_types()
?Beta Was this translation helpful? Give feedback.
All reactions