Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): treat a wildcard comment the same in every format
joshistoastd06ed578ec8d
diff --git a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.tsindex 499d7f70d5..2531931f41 100644--- a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.test.ts@@ -158,6 +158,17 @@ describe('normalizeWildcardValues', () => {it('leaves an already-clean list alone', () => {expect(normalizeWildcardValues(['red', 'green'])).toEqual(['red', 'green']);});++ // Verified against dynamicprompts itself: a value of `poster #1` expands to+ // `poster `, and `#ff0000 glow` expands to nothing. There is no escape for it,+ // so a stored `#` is text that silently never reaches the model.+ it('drops a comment, and the value that is nothing but one', () => {+ expect(normalizeWildcardValues(['poster #1', 'red # a colour', '#ff0000 glow', 'blue'])).toEqual([+ 'poster',+ 'red',+ 'blue',+ ]);+ });});describe('getWildcardValuesError', () => {diff --git a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.tsindex 679eff366d..558655187a 100644--- a/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/dynamicPrompts.ts@@ -170,14 +170,23 @@ export const getWildcardValuesError = (values: readonly string[]): 'tooManyValue};/**- * The values as they will be stored: trimmed, with the blanks dropped.+ * The values as they will be stored: comments removed, trimmed, blanks dropped.** Applied wherever a list is authored, so that what is saved is what an export* writes and a re-import reads back. Without it a stray blank line survived into* the catalog and vanished on the next round trip.+ *+ * `#` comments to end of line, and the expander applies that to a substituted+ * value as readily as to the prompt around it — a value of `poster #1` reaches+ * the model as `poster `, and `#ff0000 glow` reaches it as nothing at all. There+ * is no escape for it upstream. Dropping the comment here is what makes that+ * visible while the list is in front of the user, rather than at generation time+ * with no clue as to where the text went. The `.txt` reader has always done+ * this, being the only format with no parser of its own; the rule belongs to the+ * value rather than to the file it arrived in.*/export const normalizeWildcardValues = (values: readonly string[]): string[] =>- values.map((value) => value.trim()).filter((value) => value.length > 0);+ values.map((value) => value.split('#')[0]?.trim() ?? '').filter((value) => value.length > 0);/*** Why a wildcard name would be rejected, or `null` if it would be accepted.diff --git a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.tsindex 2261baa758..8497c0dd17 100644--- a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.test.ts@@ -56,6 +56,15 @@ describe('wildcardsFromNestedRecord', () => {]);});+ // The `.txt` reader has always stripped these. A YAML or JSON collection kept+ // them, so the same list imported two ways gave two different catalogs — and+ // the one that kept the `#` held values that expand to nothing.+ it('drops comments the way the text reader does', () => {+ expect(wildcardsFromNestedRecord({ colours: ['poster #1', '#ff0000 glow', 'blue'] })).toEqual([+ { name: 'colours', values: ['poster', 'blue'] },+ ]);+ });+it('takes a key that already contains a slash as written', () => {expect(wildcardsFromNestedRecord({ 'animals/dogs': ['corgi'] })).toEqual([{ name: 'animals/dogs', values: ['corgi'] },diff --git a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.tsindex ba5f1a18d1..5efd60d135 100644--- a/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/wildcardTransfer.ts@@ -20,7 +20,12 @@* written rather than riding along in the generate widget's chunk.*/-import { getWildcardNameError, getWildcardValuesError, MAX_WILDCARD_NAME_LENGTH } from './dynamicPrompts';+import {+ getWildcardNameError,+ getWildcardValuesError,+ MAX_WILDCARD_NAME_LENGTH,+ normalizeWildcardValues,+} from './dynamicPrompts';export interface ParsedWildcard {name: string;@@ -48,10 +53,7 @@ export const getWildcardNameFromPath = (path: string): string =>*/export const parseWildcardTextFile = (path: string, contents: string): ParsedWildcard => ({name: getWildcardNameFromPath(path),- values: contents- .split(/\r?\n/)- .map((line) => line.split('#')[0].trim())- .filter((line) => line.length > 0),+ values: normalizeWildcardValues(contents.split(/\r?\n/)),});const isPlainObject = (value: unknown): value is Record<string, unknown> =>@@ -69,10 +71,11 @@ const toValues = (value: unknown): string[] | null => {return null;}- return value- .filter((entry): entry is boolean | number | string => ['boolean', 'number', 'string'].includes(typeof entry))- .map((entry) => String(entry).trim())- .filter((entry) => entry.length > 0);+ return normalizeWildcardValues(+ value+ .filter((entry): entry is boolean | number | string => ['boolean', 'number', 'string'].includes(typeof entry))+ .map((entry) => String(entry))+ );};/**