-
Notifications
You must be signed in to change notification settings - Fork 20
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) Support Preserving Variable Values #115
(feat) Support Preserving Variable Values #115
Conversation
Updates the variable assignment command to support preserving the value of a variable if one is already declared. The new syntax adds an optional `?` preceding the `=` to indicate that the assignment should only occur if the variable does not have a value.
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #115 +/- ##
=======================================
Coverage 97.43% 97.44%
=======================================
Files 77 77
Lines 3358 3369 +11
=======================================
+ Hits 3272 3283 +11
Misses 86 86 ☔ View full report in Codecov by Sentry. |
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.
Thanks!
Beyond the inline comments, could you also update the documentation to include this feature?
tests/parser/test_parser.py
Outdated
@pytest.mark.parametrize( | ||
("immediate", "preserve"), | ||
[ | ||
(False, False), | ||
(False, True), | ||
(True, False), | ||
(True, True), | ||
], | ||
) |
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.
This will have the same combinatorial effect, plus nicer test IDs:
@pytest.mark.parametrize( | |
("immediate", "preserve"), | |
[ | |
(False, False), | |
(False, True), | |
(True, False), | |
(True, True), | |
], | |
) | |
@pytest.mark.parametrize("immediate", (False, True), ids=("delayed", "immediate")) | |
@pytest.mark.parametrize("preserve", (False, True), ids=("not-preserved", "preserved")) |
Where should this be added? It looks like all of the variable functionality is actually documented in the sd-dynamic-prompts project. |
Renamed the `preserve` property of `VariableAssignmentCommand` to overwrite, changed its default to True, and reversed how it was used that existing values are now preserved when it is not set.
Heck, that's a good question. I opened (EDIT: and merged) #117 and adieyal/sd-dynamic-prompts#701 to improve and sync the docs between the two repos, so please rebase and add the new stuff into |
I updated the pull request with a new section in SYNTAX.md |
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.
LGTM. So sorry for the review delay!
Makes a minor change to the
VariableAssignmentCommand
to include a new booleanpreserve
property, which is set by placing a?
before the=
in the assignment.Updating the
SamplingContext
to test for the newpreserve
property before processing the assignment. The value being assigned is only associated with the variable if the variable did not already exist in the context. Without thepreserve
property, the value will always be assigned.Example Wildcards:
Example Prompts:
The functionality is similar to default values for variables, but will allow the variable values to propagate to other nested prompts and retain some consistency.