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 Variable Support in Wildcard Paths #110

Merged
merged 8 commits into from
Nov 23, 2023

Conversation

mwootendev
Copy link
Contributor

Adds support for the issue described in #614 of
sd-dynamic-prompts
.
The patch adds support for allowing variable refences within wildcard
paths (e.g. __cars/${car}/types__). During the parsing phase, the
variables will be retained in the path. During sampling, before
resolving the wildcard, the variable is first resolved and replaced in
the wildcard.

The update should allow support for variable replacement, including
providing default values using the normal :default syntax.
Some examples:

  • ${gender=male}${section=upper} __clothes/${gender}/${section}__
  • __clothes/${gender:female}/${section:lower}__
  • __clothes/${gender:female}/${section:*}__

The test cases were updated to test a variety of scenarios.

Adds support for the issue described in [#614 of
sd-dynamic-prompts](adieyal/sd-dynamic-prompts#614).
The patch adds support for allowing variable refences within wildcard
paths (e.g. `__cars/${car}/types__`). During the parsing phase, the
variables will be retained in the path. During sampling, before
resolving the wildcard, the variable is first resolved and replaced in
the wildcard.

The update should allow support for variable replacement, including
providing default values using the normal `:default` syntax.
Some examples:
* `${gender=male}${section=upper} __clothes/${gender}/${section}__`
* `__clothes/${gender:female}/${section:lower}__`
* `__clothes/${gender:female}/${section:*}__`

The test cases were updated to test a variety of scenarios.
Added a test case to test the cars scenario from a YAML file discussed
in sd-dynamic-prompts #164. Added the example wildcard file, and a test
case a utilitizes it.
@akx akx self-requested a review November 20, 2023 06:34
@akx akx added the enhancement New feature or request label Nov 20, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 20, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (510d1e9) 97.47% compared to head (99778b7) 97.43%.

Files Patch % Lines
src/dynamicprompts/samplers/utils.py 88.57% 4 Missing ⚠️

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
- Coverage   97.47%   97.43%   -0.05%     
==========================================
  Files          77       77              
  Lines        3249     3352     +103     
==========================================
+ Hits         3167     3266      +99     
- Misses         82       86       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@akx akx left a comment

Choose a reason for hiding this comment

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

Thanks, looks very neat!

Our linters are complaining about a bunch of things (I just landed #111 to make Ruff speak GitHub Actions annotations, to make them easier to see, so if you rebase to the current main, you should see them here in GitHub too). You can install pre-commit from pip and run pre-commit run --all-files to apply all relevant auto-fixes.

Beyond that, there's a couple of comments within the PR that I think would be neat to address now.

src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
tests/samplers/test_common.py Outdated Show resolved Hide resolved
src/dynamicprompts/parser/parse.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
@mwootendev
Copy link
Contributor Author

@akx Thank you for the in-depth feedback. I'll be honest, this is my first time trying work with Python, so I'm unfamiliar with many of the idioms. I've mostly done Java, JavaScript, and TypeScript development, so I appreciate the Python guidance. I hope this last update resolved all of your concerns.

Copy link
Collaborator

@akx akx left a comment

Choose a reason for hiding this comment

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

Couple more smaller comments this time around.

Great stuff for someone who hasn't touched Python much! 💪

src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Outdated Show resolved Hide resolved
src/dynamicprompts/samplers/utils.py Show resolved Hide resolved
src/dynamicprompts/parser/parse.py Outdated Show resolved Hide resolved
@akx
Copy link
Collaborator

akx commented Nov 22, 2023

@mwootendev Tests seem to be now failing 😩

@mwootendev
Copy link
Contributor Author

@mwootendev Tests seem to be now failing 😩

This should be resolved in the latest push. In the case where the variable was None it failed that check.

Copy link
Collaborator

@akx akx left a comment

Choose a reason for hiding this comment

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

LGTM, thank you! 🎉

@akx akx merged commit ff47441 into adieyal:main Nov 23, 2023
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants