Extensions/DynamicPrompts Custom Nodes
ComfyUI Extension

DynamicPrompts Custom Nodes

Nodes: Random Prompts, Combinatorial Prompts, I'm Feeling Lucky, Magic Prompt, Jinja2 Templates. ComfyUI-DynamicPrompts is a custom nodes library that integrates into your existing ComfyUI Library. It provides nodes that enable the use of Dynamic Prompts in your ComfyUI.

By adieyal·Created 3 years ago·Updated 5 days ago· 448
adieyal/comfyui-dynamicprompts
Nodes5
On cloudLocal install
CategoryDynamic Prompts, utils
Stars448
Updated5 days ago
Readme

Dynamic Prompts for ComfyUI

<img src="images/example.png"/>

ComfyUI nodes for Dynamic Prompts: write one template such as a {red|green|blue} car by the {sea|mountains} and get a different prompt on each run, or step through every combination. Wildcard files, Jinja2 templates and Magic Prompt are supported too.

Nodes

All nodes are in the Dynamic Prompts category.

| Node | What it does | |---|---| | Random Prompts | Picks one random variant for each {...} and wildcard in the template. | | Combinatorial Prompts | Steps through every combination of the template, one per run. | | Jinja2 Templates | Renders a Jinja2 template; templates can call wildcard("...") and include other templates from the wildcard folders. | | Magic Prompt | Expands the prompt with a small language model that adds style and detail modifiers. |

The template syntax (variants, wildcards, weights, variables and more) is described in the Dynamic Prompts syntax guide.

OutputString, from earlier versions, is deprecated: it still loads in old workflows but is hidden from search. Use ComfyUI's Preview Any node to see a generated prompt.

Installation

ComfyUI-Manager: open the Manager, choose Custom Nodes Manager, search for dynamicprompts and install Dynamic Prompts. Restart ComfyUI.

comfy-cli:

comfy node install comfyui-dynamicprompts

Manually, from the ComfyUI folder:

git clone https://github.com/adieyal/comfyui-dynamicprompts custom_nodes/comfyui-dynamicprompts
python -m pip install -r custom_nodes/comfyui-dynamicprompts/requirements.txt

Then restart ComfyUI.

Using the nodes

Double-click the canvas and search for a node by name (for example Random Prompts), or open the Nodes sidebar and look under Dynamic Prompts in the Extensions section.

<img src="images/menu.png" width="300"/>

Each node outputs a STRING. To use it as a prompt, drag the STRING output onto the text box of CLIP Text Encode (or any node with a text input); the text box turns into an input. Add a second node for the negative prompt if you want that randomised too.

Seeds and refreshing

  • Random Prompts: the same template, seed and wildcard files always give the same prompt. Set the seed's control after generate to randomize for a new prompt each run, or set autorefresh to Yes to ignore the seed.
  • Combinatorial Prompts has an index instead of a seed. It picks which combination to output, and wraps around. The combinations output gives the exact total, however large the template. Control after generate starts at increment, so successive runs walk through every combination: a {red|green|blue} ball gives a red ball, a green ball, a blue ball, then a red ball again. Random parts of the template ({~a|b}) are fixed by the index, so the same index always gives the same prompt, and a second pass through the combinations gets fresh random choices. There is no autorefresh; set the control to randomize for a random combination each run.
  • Magic Prompt works like Random Prompts.
  • Jinja2 Templates has no seed. The result is reused until the template or a wildcard file changes; set autorefresh to Yes to render it again on every run.

Saving the prompt in the image

ComfyUI's image metadata stores the template (a {red|blue} ball), not the prompt that was generated. Set save_to_metadata to Yes on a node to also store the generated prompt: images saved with Save Image get a dynamicprompts entry such as {"5": "a blue ball"}, keyed by node id. With this on, the node runs on every queue instead of being cached, because a cached node can't write metadata.

Wildcards

Put wildcard files in ComfyUI/wildcards or in the extension's own wildcards folder. More folders can be added under a wildcards key in ComfyUI's extra_model_paths.yaml. Files can be .txt, .json or .yaml (see file formats), and a file at wildcards/animals/cats.txt is used as __animals/cats__. Edits are picked up on the next run without restarting ComfyUI.

Ready-made collections to start with:

Magic Prompt

Magic Prompt uses the MagicPrompt-Stable-Diffusion model, which is downloaded (about 500 MB) the first time the node runs and kept in the Hugging Face cache (~/.cache/huggingface, or HF_HOME). It needs the transformers package, which ComfyUI already installs; the extension doesn't install or change it. If the download fails, the error is shown in ComfyUI and the next run tries again.

Example workflows

The example_workflows folder has a workflow for each node. Drag one onto the ComfyUI canvas to load it. They use the Stable Diffusion 1.5 checkpoint v1-5-pruned-emaonly; pick any checkpoint you have in Load Checkpoint.

Links