Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
2 : import { processDynamicPrompt } from '@/utils/formatUtil'
3 : import type { ComfyExtension } from '@/types/comfy'
4 :
5 : // Allows for simple dynamic prompt replacement
6 : // Inputs in the format {a|b} will have a random value of a or b chosen when the prompt is queued.
7 :
8 2355 : export const dynamicPromptsExtension: ComfyExtension = {
9 : name: 'Comfy.DynamicPrompts',
10 : nodeCreated(node: LGraphNode) {
11 23115 : if (node.widgets) {
12 19804 : const widgets = node.widgets.filter((w) => w.dynamicPrompts)
13 19804 : for (const widget of widgets) {
14 5967 : widget.serializeValue = () => {
15 250 : if (typeof widget.value !== 'string') return widget.value
16 :
17 250 : return processDynamicPrompt(widget.value)
18 : }
19 : }
20 : }
21 : }
22 : }
|