diff --git a/src/renderer/extensions/firstRunTour/roles/heuristicRoles.test.ts b/src/renderer/extensions/firstRunTour/roles/heuristicRoles.test.ts index 265b2cd0039..16668132bf1 100644 --- a/src/renderer/extensions/firstRunTour/roles/heuristicRoles.test.ts +++ b/src/renderer/extensions/firstRunTour/roles/heuristicRoles.test.ts @@ -330,7 +330,12 @@ describe('heuristicRoles', () => { 'negatives', 'NEGATIVEPROMPT', 'Undesired content', - 'Things to avoid' + 'Things to avoid', + 'Anti-prompt', + 'anti prompt', + 'AntiPrompt', + 'ANTIPROMPT', + 'anti_prompts' ])('reads %s as a negative prompt rather than the prompt', (title) => { const graph = createTestRootGraph() addWiredSink(graph) @@ -342,7 +347,54 @@ describe('heuristicRoles', () => { ).toBeNull() }) - it.for(['Antique portrait', 'Negro', 'negate mask', 'anti_aliasing'])( + it('reads a widget named anti_prompt as a negative prompt', () => { + const graph = createTestRootGraph() + addWiredSink(graph) + addNode(graph, 'CustomEncode', { prompts: ['anti_prompt'] }) + + expect( + heuristicRoles(graph)?.prompt, + 'the widget name names the box just as the node title does' + ).toBeNull() + }) + + it('reads the anti_prompt input a box feeds as a negative prompt', () => { + const graph = createTestRootGraph() + addWiredSink(graph) + const text = addNode(graph, 'CLIPTextEncode', { + prompts: ['text'], + outputs: ['CONDITIONING'] + }) + const sampler = addNode(graph, 'CustomSampler', { + inputs: ['anti_prompt'], + inputType: 'CONDITIONING' + }) + text.connect(0, sampler, 0) + + expect( + heuristicRoles(graph)?.prompt, + 'the input a box feeds names it, the same as its own title would' + ).toBeNull() + }) + + it('reads a subgraph port named Anti-Prompt as a negative prompt', () => { + const graph = createTestRootGraph() + addWiredSink(graph) + addExposedPrompt(graph, 'Anti-Prompt') + + expect( + heuristicRoles(graph)?.prompt, + 'the exposed port is the only label on an interior node titled nothing useful' + ).toBeNull() + }) + + it.for([ + 'Antique portrait', + 'Negro', + 'negate mask', + 'anti_aliasing', + 'antialiasing strength' + ])( 'still offers %s as the prompt, since only its spelling looks negative', (title) => { const graph = createTestRootGraph() diff --git a/src/renderer/extensions/firstRunTour/roles/heuristicRoles.ts b/src/renderer/extensions/firstRunTour/roles/heuristicRoles.ts index 8e4bad9ff72..3f9e0e0c9d9 100644 --- a/src/renderer/extensions/firstRunTour/roles/heuristicRoles.ts +++ b/src/renderer/extensions/firstRunTour/roles/heuristicRoles.ts @@ -28,10 +28,20 @@ const MEDIA_KIND_BY_SLOT_TYPE: Partial> = { * `negate`, `negligible` and Spanish `negro` disqualify a real prompt. */ const DISQUALIFYING = ['negative', 'neg', 'system', 'undesired', 'avoid'] +/** `anti` names the negative box only next to the noun — `Anti-prompt`, + * `AntiPrompt`, `ANTIPROMPT` — since `anti_aliasing` and `antique` are ordinary + * words a real prompt carries. Read off the normalised label, not its words, so + * the pair survives the separator and camelCase spellings alike. */ +const ANTI_PROMPT = /\banti ?prompts?\b/ + function disqualified(word: string): boolean { return DISQUALIFYING.includes(word) || word.startsWith('negative') } +function readsAsAntiPrompt(label: string | undefined): boolean { + return ANTI_PROMPT.test(labelWords(label).join(' ')) +} + /** Real templates ship nodes with no title and widgets with no name. */ function labelWords(label: string | undefined): string[] { return (label ?? '') @@ -95,6 +105,7 @@ function promptScore(labels: string[], fedInputNames: string[]): number { const fed = fedInputNames.flatMap(labelWords) if ([...words, ...fed].some(disqualified)) return -1 + if ([...labels, ...fedInputNames].some(readsAsAntiPrompt)) return -1 if (fed.includes('positive')) return 3 if (words.includes('positive')) return 2 if (words.includes('prompt')) return 1