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

feat: Add Literal["*"] option to required_variables in ChatPrompBuilder and PromptBuilder #8572

Merged
merged 4 commits into from
Nov 22, 2024

Conversation

sjrl
Copy link
Contributor

@sjrl sjrl commented Nov 22, 2024

Related Issues

Proposed Changes:

Based on the discussion we added the ability to pass "*" as a Literal option to required_variables in the ChatPromptBuilder and PromptBuilder to automatically set all variables in the template as required without needing to specify them manually.

How did you test it?

added unit tests

Notes for the reviewer

Checklist

@sjrl sjrl requested review from a team as code owners November 22, 2024 13:27
@sjrl sjrl requested review from dfokina and julian-risch and removed request for a team November 22, 2024 13:27
@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels Nov 22, 2024
@coveralls
Copy link
Collaborator

coveralls commented Nov 22, 2024

Pull Request Test Coverage Report for Build 11973875336

Details

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

Files with Coverage Reduction New Missed Lines %
components/builders/chat_prompt_builder.py 1 98.55%
Totals Coverage Status
Change from base Build 11973695900: 0.009%
Covered Lines: 7880
Relevant Lines: 8728

💛 - Coveralls

@@ -211,12 +213,16 @@ def _validate_variables(self, provided_variables: Set[str]):
:raises ValueError:
If no template is provided or if all the required template variables are not provided.
"""
missing_variables = [var for var in self.required_variables if var not in provided_variables]
if self.required_variables == "*":
required_variables = sorted(self.variables)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason why we want to sort the variables here? self.required_variables is also not sorted right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah specifically here b/c self.variables is a list but is created from a Set. So in this specific scenario it's possible for the order of required_variables to change when inheriting from self.variables which causes the Error message to be inconsistent. We look for an exact string match for one of the tests so without the sort the test would become unreliable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.required_variables doesn't need to be sorted because if it comes in as a List we have no issue in regards to order.

Copy link
Contributor

@silvanocerza silvanocerza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@sjrl sjrl merged commit eace2a9 into main Nov 22, 2024
18 checks passed
@sjrl sjrl deleted the issue-8395 branch November 22, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
4 participants