Skip to content

Commit

Permalink
Don't strip separators from join results we didn't add in the first p…
Browse files Browse the repository at this point in the history
  • Loading branch information
akx authored Nov 12, 2023
1 parent 3af83a1 commit d031416
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/dynamicprompts/sampling_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ def joined(
) -> SamplingResult:
from dynamicprompts.utils import removeprefix, removesuffix

joined = separator.join(r.text for r in results)
results_list = list(results)

if len(results_list) == 1:
# Special case: when we have a single result,
# there's no point in joining anything, or doing
# the special handling to strip separators (since
# we never added any). This means that a separator
# in the input will be preserved; this is intentional.
return results_list[0]

joined = separator.join(r.text for r in results_list)

if separator:
joined = removeprefix(joined, separator)
joined = removesuffix(joined, separator)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sd_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,11 @@ def test_sd_665():
wi = list(_parse_structured_file_list([expr]))
assert len(wi) == 1
assert wi[0] == expr


def test_sd_672(wildcard_manager: WildcardManager):
# https://github.com/adieyal/sd-dynamic-prompts/discussions/672

tpl = "{|hot,}{|summer,}{|blue sky,}"
generator = CombinatorialPromptGenerator(wildcard_manager)
assert any("," in prompt for prompt in generator.generate(tpl))

0 comments on commit d031416

Please sign in to comment.