allow longer substitutions without quotes for cross attention swap

This commit is contained in:
Damian at mba 2022-10-24 00:22:14 +02:00
parent 92c6a3812d
commit 2619a0b286
2 changed files with 9 additions and 1 deletions

View File

@ -495,7 +495,7 @@ def build_parser_syntax(attention_plus_base: float, attention_minus_base: float)
edited_fragment = pp.MatchFirst([
lparen +
(quoted_fragment |
pp.Group(pp.Word(pp.printables, exclude_chars=string.whitespace + ',').set_parse_action(make_text_fragment))
pp.Group(pp.OneOrMore(pp.Word(pp.printables, exclude_chars=string.whitespace + ',').set_parse_action(make_text_fragment)))
) +
pp.Dict(pp.OneOrMore(comma + cross_attention_option)) +
rparen,

View File

@ -269,6 +269,14 @@ class PromptParserTestCase(unittest.TestCase):
Fragment('eating a hotdog', 1)])]),
parse_prompt("a \"cat\".swap(dog, t_start=0.1, s_start=20) eating a hotdog"))
self.assertEqual(
Conjunction([
FlattenedPrompt([Fragment('a fantasy forest landscape', 1),
CrossAttentionControlSubstitute([Fragment('', 1)], [Fragment('with a river', 1)],
options={'s_start': 0.8, 't_start': 0.8})])]),
parse_prompt("a fantasy forest landscape \"\".swap(with a river, s_start=0.8, t_start=0.8)"))
def test_escaping(self):
# make sure ", ( and ) can be escaped