Skip to content

Commit 7e45fba

Browse files
authored
Fix prompt parser default step transformer w/ test
1 parent 5830095 commit 7e45fba

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎modules/prompt_parser.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from typing import List
44
import lark
55

6+
try:
7+
from modules.shared import opts
8+
except:
9+
pass
10+
611
# a prompt like this: "fantasy landscape with a [mountain:lake:0.25] and [an oak:a christmas tree:0.75][ in foreground::0.6][ in background:0.25] [shoddy:masterful:0.5]"
712
# will be represented with prompt_schedule like this (assuming steps=100):
813
# [25, 'fantasy landscape with a mountain and an oak in foreground shoddy']
@@ -49,6 +54,8 @@ def get_learned_conditioning_prompt_schedules(prompts, steps):
4954
[[5, 'a c'], [10, 'a {b|d{ c']]
5055
>>> g("((a][:b:c [d:3]")
5156
[[3, '((a][:b:c '], [10, '((a][:b:c d']]
57+
>>> g("[a|(b:1.1)]")
58+
[[1, 'a'], [2, '(b:1.1)'], [3, 'a'], [4, '(b:1.1)'], [5, 'a'], [6, '(b:1.1)'], [7, 'a'], [8, '(b:1.1)'], [9, 'a'], [10, '(b:1.1)']]
5259
"""
5360

5461
def collect_steps(steps, tree):
@@ -84,7 +91,13 @@ def plain(self, args):
8491
yield args[0].value
8592
def __default__(self, data, children, meta):
8693
for child in children:
87-
yield from child
94+
try:
95+
if opts.use_old_prompt_parser_default_step_transformer:
96+
yield from child
97+
else:
98+
yield child
99+
except:
100+
yield child
88101
return AtStep().transform(tree)
89102

90103
def get_schedule(prompt):

0 commit comments

Comments
 (0)