haystack icon indicating copy to clipboard operation
haystack copied to clipboard

feat: add custom jinja filter handling to ConditionalRouter

Open ChrisPappalardo opened this issue 1 year ago • 3 comments

Related Issues

  • fixes #7940

Proposed Changes:

Added a custom_filters: Optional[Dict[str, Callable]] field to the ConditionalRouter constructor to allow users to pass in and use custom Jinja2 filters when creating route conditions. Also added the same field to from_dict to allow users to provide callables when de-serializing a ConditionalRouter that was serialized with custom filters.

How did you test it?

Added 3 unit tests to test/components/routers/test_conditional_router.py:

  • test_custom_filter - ensures a custom test filter works with the router
  • test_custom_filter_serialization - ensures the router with the custom filter attribute can be serialized and de-serialized
  • test_custom_filter_bad_deserialization - ensures that a custom exception is generated when a router with custom filers is deserialized without providing callables

Notes for the reviewer

I updated the docstring with usage information, but not sure what your documentation requirements are otherwise.

Checklist

ChrisPappalardo avatar Jun 28 '24 21:06 ChrisPappalardo

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jun 28 '24 21:06 CLAassistant

Pull Request Test Coverage Report for Build 9718882629

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 89.989%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 2 97.5%
<!-- Total: 2
Totals Coverage Status
Change from base Build 9710252897: 0.01%
Covered Lines: 6751
Relevant Lines: 7502

💛 - Coveralls

coveralls avatar Jun 29 '24 09:06 coveralls

Pull Request Test Coverage Report for Build 9724715471

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 89.989%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 2 97.5%
<!-- Total: 2
Totals Coverage Status
Change from base Build 9710252897: 0.01%
Covered Lines: 6751
Relevant Lines: 7502

💛 - Coveralls

coveralls avatar Jun 29 '24 15:06 coveralls

Not sure what to do about these integration test errors (all seem related to OpenAI): image image

ChrisPappalardo avatar Jun 30 '24 13:06 ChrisPappalardo

Indeed unrelated, thanks @ChrisPappalardo we'll take a look at integrating this one soon 🙏

vblagoje avatar Jun 30 '24 14:06 vblagoje

@shadeMe it would be nice to include this one in the upcoming release, if possible 😄

vblagoje avatar Jul 01 '24 08:07 vblagoje

Pull Request Test Coverage Report for Build 9740569615

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.01%) to 89.989%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 2 97.5%
<!-- Total: 2
Totals Coverage Status
Change from base Build 9740565126: 0.01%
Covered Lines: 6751
Relevant Lines: 7502

💛 - Coveralls

coveralls avatar Jul 01 '24 09:07 coveralls

Pull Request Test Coverage Report for Build 9768491597

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 89.976%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 2 97.4%
<!-- Total: 2
Totals Coverage Status
Change from base Build 9758508178: 0.008%
Covered Lines: 6750
Relevant Lines: 7502

💛 - Coveralls

coveralls avatar Jul 03 '24 07:07 coveralls

Pull Request Test Coverage Report for Build 9779774624

Warning: 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

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 89.997%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 2 97.4%
<!-- Total: 2
Totals Coverage Status
Change from base Build 9758508178: 0.03%
Covered Lines: 6766
Relevant Lines: 7518

💛 - Coveralls

coveralls avatar Jul 03 '24 14:07 coveralls

Pull Request Test Coverage Report for Build 9782596228

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 89.997%

Files with Coverage Reduction New Missed Lines %
components/routers/conditional_router.py 2 97.4%
<!-- Total: 2
Totals Coverage Status
Change from base Build 9777342637: 0.008%
Covered Lines: 6766
Relevant Lines: 7518

💛 - Coveralls

coveralls avatar Jul 03 '24 20:07 coveralls

Thanks for this amazing contribution @ChrisPappalardo Keep them coming!

vblagoje avatar Jul 04 '24 08:07 vblagoje

Happy to contribute, I'm a fan of this project!

ChrisPappalardo avatar Jul 04 '24 12:07 ChrisPappalardo