adieyal / dynamicprompts

Templating language for generating prompts for text to image generators such as Stable Diffusion
MIT License
124 stars 20 forks source link

(feat) Support Preserving Variable Values #115

Closed mwootendev closed 8 months ago

mwootendev commented 11 months ago

Makes a minor change to the VariableAssignmentCommand to include a new boolean preserve property, which is set by placing a ? before the = in the assignment.

Updating the SamplingContext to test for the new preserve 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 the preserve property, the value will always be assigned.

Example Wildcards:

vartest:
  prompt:
    - '${subject?=!{man|woman}} ${weather=!{sun|rain}} ${drink?=!{__vartest/drink__}} a ${subject} standing in the ${weather} drinking ${drink}'
  drink:
    - coffee
    - tea
  winter:
    - '${weather=snow} ${drink=hot chocolate} __vartest/prompt__'

Example Prompts:

${subject=boy} __vartest/prompt__ a boy standing in the rain drinking tea

${subject=cowboy} ${weather=sun} ${drink=sasparilla} __vartest/prompt__ a cowboy standing in the sun drinking sasparilla

__vartest/winter__ a woman standing in the snow drinking hot chocolate

${subject=boy} ${weather=rain} ${drink=iced tea} __vartest/winter__ a boy standing in the snow drinking hot chocolate

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.

codecov-commenter commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e377980) 97.43% compared to head (8e74296) 97.44%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #115 +/- ## ======================================= Coverage 97.43% 97.44% ======================================= Files 77 77 Lines 3358 3369 +11 ======================================= + Hits 3272 3283 +11 Misses 86 86 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mwootendev commented 10 months ago

Thanks!

Beyond the inline comments, could you also update the documentation to include this feature?

Where should this be added? It looks like all of the variable functionality is actually documented in the sd-dynamic-prompts project.

akx commented 10 months ago

Where should this be added? It looks like all of the variable functionality is actually documented in the sd-dynamic-prompts project.

Heck, that's a good question. I opened (EDIT: and merged) https://github.com/adieyal/dynamicprompts/pull/117 and https://github.com/adieyal/sd-dynamic-prompts/pull/701 to improve and sync the docs between the two repos, so please rebase and add the new stuff into docs/SYNTAX.md :)

mwootendev commented 10 months ago

Where should this be added? It looks like all of the variable functionality is actually documented in the sd-dynamic-prompts project.

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 docs/SYNTAX.md :)

I updated the pull request with a new section in SYNTAX.md

mwootendev commented 10 months ago

@akx @adieyal are there additional changes needed?