-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: Add variable to specify inputs as optional to ConditionalRouter #8568
Conversation
Pull Request Test Coverage Report for Build 11974160625Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
@silvanocerza @sjrl - if I understood correctly the originating issue this seems like a relatively simple fix. Added a bunch of tests, maybe a bit more than needed just to make sure as this is an important component. |
# When 'path' is provided, specific route is taken: | ||
result = router.run(question="What?", path="rag") | ||
assert result == {"rag_route": "What?"} | ||
|
||
# When 'path' is not provided, fallback route is taken: | ||
result = router.run(question="What?") | ||
assert result == {"default_route": "What?"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good example! Except this example actually works pre your changes. To get the error we were originally seeing you would need to put it in a Pipeline first. Even a single component pipeline would do. Otherwise it's a bit misleading here since this example would actually work without specifying the optional_variables
parameter.
warn( | ||
f"The following optional variables are specified but not used in any route: {unused_optional_vars}. " | ||
"Check if there's a typo in variable names.", | ||
UserWarning, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use the logger.warning
here instead or in addition to? Using the logger allows us to surface these warnings to users in dC more easily.
Yeah this looks like it solves the issue thanks @vblagoje ! |
Why:
Enhances the ConditionalRouter component by adding support for optional parameters, enabling default/fallback routing behavior when certain inputs are not provided at runtime.
What:
Introduces
optional_variables
parameter to specify which route variables can be omittedImproves documentation with clear examples of fallback routing patterns
Implements proper serialization/deserialization for the new field
How can it be used:
Define routes with fallback behavior when certain parameters are missing:
How did you test it:
Unit tests verify both direct component usage and pipeline integration
Tests cover simple and complex scenarios with and without optional parameters