@@ -160,27 +160,30 @@ test("numbers past the request bounds are reported as clamped", () => {
160160 ] ) ;
161161} ) ;
162162
163- // Prompt content, not a key: A1111 attention syntax is kept in the prompt and named as plain text
164- // unless the engine (sd.cpp) parses it .
165- const PROMPT_CONTENT : Array < [ string , string [ ] ] > = [
166- [ "a (red:1.2) car" , [ "(red:1.2)" ] ] ,
167- [ "a ((red)) car, [blurry]" , [ "((red))" , "[blurry]" ] ] ,
168- [ "a \\(literal\\) car \\[x\\]" , [ ] ] ,
169- [ "a (red car" , [ ] ] ,
170- [ "plain text" , [ ] ] ,
163+ // Prompt content, not a key: A1111 attention syntax and its escaped literal brackets are kept in the
164+ // prompt as written and named unless the engine (sd.cpp) parses A1111 syntax itself .
165+ const PROMPT_CONTENT : Array < [ string , string [ ] , string [ ] ] > = [
166+ [ "a (red:1.2) car" , [ "(red:1.2)" ] , [ ] ] ,
167+ [ "a ((red)) car, [blurry]" , [ "((red))" , "[blurry]" ] , [ ] ] ,
168+ [ "a \\(literal\\) car \\[x\\]" , [ ] , [ "\\(" , "\\)" , "\\[" , "\\]" ] ] ,
169+ [ "a (red car" , [ ] , [ ] ] ,
170+ [ "plain text" , [ ] , [ ] ] ,
171171] ;
172172
173- for ( const [ prompt , groups ] of PROMPT_CONTENT ) {
174- test ( `prompt emphasis in ${ JSON . stringify ( prompt ) } ` , ( ) => {
173+ for ( const [ prompt , groups , escaped ] of PROMPT_CONTENT ) {
174+ test ( `prompt content in ${ JSON . stringify ( prompt ) } ` , ( ) => {
175175 assert . deepEqual ( promptEmphasisGroups ( prompt ) , groups ) ;
176176 const r = parseA1111Parameters ( `${ prompt } \nNegative prompt: (worst quality:1.4)\n${ BASE . split ( "\n" ) [ 1 ] } ` ) ;
177177 assert . ok ( r ) ;
178178 assert . equal ( r . prompt , prompt ) ;
179179 const all = [ ...groups , "(worst quality:1.4)" ] ;
180- assert . deepEqual ( importNotApplied ( r , "sdxl" ) , [
180+ const expected = [
181181 `prompt emphasis (${ all . slice ( 0 , 3 ) . join ( ", " ) } ${ all . length > 3 ? ", ..." : "" } ) is passed as plain text` ,
182- ] ) ;
183- // The native sd.cpp engine reads the weights itself.
182+ ] ;
183+ if ( escaped . length > 0 )
184+ expected . push ( `escaped brackets (${ escaped . join ( " " ) } ) are passed with their backslashes` ) ;
185+ assert . deepEqual ( importNotApplied ( r , "sdxl" ) , expected ) ;
186+ // The native sd.cpp engine reads A1111 syntax itself.
184187 assert . deepEqual ( importNotApplied ( r , "sdxl" , true ) , [ ] ) ;
185188 } ) ;
186189}
0 commit comments