Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions src/renderer/extensions/firstRunTour/roles/heuristicRoles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/extensions/firstRunTour/roles/heuristicRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ const MEDIA_KIND_BY_SLOT_TYPE: Partial<Record<string, TourMediaKind>> = {
* `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 ?? '')
Expand Down Expand Up @@ -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
Expand Down
Loading