-
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 Literal["*"] option to required_variables in ChatPrompBuilder and PromptBuilder #8572
Conversation
Pull Request Test Coverage Report for Build 11973875336Details
💛 - 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) |
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.
Any specific reason why we want to sort the variables here? self.required_variables is also not sorted right?
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.
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.
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.
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.
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.
Looks good to me 👍
Related Issues
"*"
to require all defined jinja variables #8395Proposed Changes:
Based on the discussion we added the ability to pass
"*"
as a Literal option torequired_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
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
.