Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable to specify inputs as optional to ConditionalRouter #8556

Closed
sjrl opened this issue Nov 19, 2024 · 0 comments · Fixed by #8568
Closed

Add variable to specify inputs as optional to ConditionalRouter #8556

sjrl opened this issue Nov 19, 2024 · 0 comments · Fixed by #8568
Assignees
Labels
P1 High priority, add to the next sprint
Milestone

Comments

@sjrl
Copy link
Contributor

sjrl commented Nov 19, 2024

Is your feature request related to a problem? Please describe.
We are using a conditional router to route to different pipeline branches based on a parameter we insert during runtime. We would like to also set a default branch in case the respective parameter (path) was not inserted at runtime.

Through testing we figured out this works if you run the component individually. So

from haystack.components.routers import ConditionalRouter

routes = [
    {
        "condition": '{{path == "rag"}}',
        "output": "{{question}}",
        "output_name": "normal",
        "output_type": str
    },
    {
        "condition": '{{path == "followup_short"}}',
        "output": "{{question}}",
        "output_name": "followup_short",
        "output_type": str
    },
    {
        "condition": '{{path == "followup_elaborate"}}',
        "output": "{{question}}",
        "output_name": "followup_elaborate",
        "output_type": str
    },
    {
        "condition": "{{ True }}",
        "output": "{{ question }}",
        "output_name": "fallback",
        "output_type": str
    }
]

router = ConditionalRouter(routes)

res = router.run(question="What?")
print(res)

However, when inserting it into a Pipeline it no longer works

from haystack import Pipeline
from haystack.components.routers import ConditionalRouter

routes = [
    {
        "condition": '{{path == "rag"}}',
        "output": "{{question}}",
        "output_name": "normal",
        "output_type": str
    },
    {
        "condition": '{{path == "followup_short"}}',
        "output": "{{question}}",
        "output_name": "followup_short",
        "output_type": str
    },
    {
        "condition": '{{path == "followup_elaborate"}}',
        "output": "{{question}}",
        "output_name": "followup_elaborate",
        "output_type": str
    },
    {
        "condition": "{{ True }}",
        "output": "{{ question }}",
        "output_name": "fallback",
        "output_type": str
    }
]

router = ConditionalRouter(routes)
pipe = Pipeline()
pipe.add_component("router", router)


res = pipe.run(data={"router": {"question": "What?"}})
print(res)

It would be great to add a way to make parameters (or some of them optional). Perhaps following the PromptBuilder we could add a required_variables parameter or do the inverse (to not cause a breaking change) and make optional_variables list so that all parameters are required by default (current behavior) and then explicitly add some as optional.

@sjrl sjrl changed the title Make inputs to ConditionalRouter optional Add variable to specify inputs as optional to ConditionalRouter Nov 19, 2024
@julian-risch julian-risch added the P1 High priority, add to the next sprint label Nov 19, 2024
@julian-risch julian-risch added this to the 2.8.0 milestone Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High priority, add to the next sprint
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants