ComfyUI Extension: ComfyUI Prompt Companion
A node that lets you save and reuse parts of prompts (embeddings, quality keywords, and so on.)
Custom Nodes (0)
README
ComfyUI Prompt Companion
A ComfyUI extension for saving, organizing, and mixing up parts of prompts ("subprompts"). Supports nested subprompts, automatic loading of specific subprompts based on selected checkpoint, and more!
๐ค Why use this?
As I was learning ComfyUI, I found that keeping my prompts up to date with my experimental workflows was taking a lot of time. A few examples:
- Manually switching between different embeddings (like
lazyneg
) when switching between checkpoints from different base models. - Remembering which quality keywords worked well with which checkpoints, and manually switching between them.
- For advanced workflows involving multiple prompts, like rendering/combining multiple images, regional prompting, attention coupling, etc. - ensuring that you're using consistent style and quality keywords across all your prompts.
- Sharing consistent "base" prompts across characters. For example: if you have a set of unique prompts for specific fantasy characters, but all including the same style keywords, and you want to update the style keywords for all those characters at once.
Prompt Companion aims to solve all of those.
๐ Neat! How do I get it?
Same as most ComfyUI custom nodes.
Quick Install (Recommended)
- Install ComfyUI.
- Install ComfyUI-Manager.
- Look up "ComfyUI Prompt Companion" in ComfyUI-Manager and install.
- Restart ComfyUI.
- The Prompt Companion node will be available in the
prompt-companion
category.
Manual Install
-
Clone this repository to your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes/ git clone https://github.com/jfcantu/ComfyUI-Prompt-Companion.git
-
The Prompt Companion node will be available in the
prompt-companion
category.
๐จ Okay, now how do I use it?
I've tried to make the nodes as intuitive as possible, so here's a quick example workflow to cover the basics:
First things first: the subprompts used here were created using the "Edit Subprompts" dialog, which can be accessed by right-clicking any Prompt Companion node.
- The "Load Checkpoint With Subprompt" node loads the checkpoint. Note that the checkpoint file is in a subfolder, (
sd15/
). Any subprompts with the trigger wordsd15
will be merged together and exported from thesubprompt
output.- You can see the output in the top flow: a negative subprompt that simply says
embedding: SD15\easynegative
.
- You can see the output in the top flow: a negative subprompt that simply says
- The subprompt is passed into the "Add Subprompt" node.
- This node now has three subprompts to merge:
input
: the input from the previous node.subprompt
: the subprompt selected from thesubprompt_selection
drop-down.textbox
: the contents of the textbox on the node itself.
- It merges them using the order specified in
merge_order
.
- This node now has three subprompts to merge:
- The resulting output is seen on the right: positive and negative prompts made from combining the input, subprompt, and textbox (in that order, as specified in
merge_order
.) - The text can then be used as input to CLIP Text Encode.
In addition to the functional nodes, there are a couple conversion nodes for converting/deconverting between subprompts and positive/negative string pairs.
๐ฒ Pretty neat! How can I learn more?
Give USAGE.md a read. It even has pictures!
๐งช Development
Setup
To install the dev dependencies and pre-commit:
cd ComfyUI-Prompt-Companion
pip install -e .[dev]
pre-commit install
Project Structure
The architecture is organized into specialized modules for maintainability and scalability:
custom_nodes/ComfyUI-Prompt-Companion/
โโโ __init__.py # Node package definition
โโโ pyproject.toml # Python project definition
โโโ api_routes.py # Definition of API routes
โ
โโโ nodes/
โ โโโ __init__.py # ComfyUI node definitions
โ โโโ prompt_nodes.py # Subprompt-related notes
โ โโโ checkpoint_loader.py # Checkpoint loader with trigger-word support
โ
โโโ core/ # Storage & Logic
โ โโโ __init__.py # Core module exports
โ โโโ storage.py # UUID-based storage with atomic operations
โ โโโ subprompt.py # Subprompt class with circular reference detection
โ โโโ folder.py # Hierarchical folder management
โ โโโ validation.py # Data validation
โ
โโโ web/ # Frontend Components
โ โโโ edit_dialog.js # Dialog for editing subprompts
โ โโโ tree_view.js # Tree-view control for use in the dialog
โ โโโ extensions.js # ComfyUI integration extensions
โ โโโ prompt_companion.css # Visual hierarchy styling
โ
โโโ doc/ # Documentation & Assets
โโโ USAGE.md # Usage documentation
โโโ *.png # Screenshot assets
Key File Responsibilities
Core Storage System
core/storage.py
: UUID-based storage with thread-safe operations, atomic file writes, cascade deletion, and backup/restore capabilitiescore/subprompt.py
: Subprompt class with nested resolution, circular reference detection, and validationcore/folder.py
: Hierarchical folder management with UUID-based identificationcore/validation.py
: Validation rules for data integrity
Node Integration
nodes/prompt_nodes.py
: ComfyUI nodes with dynamic combo boxes, IS_CHANGED method for cache invalidation, and six merge order permutationsnodes/checkpoint_loader.py
: Checkpoint loading with trigger word matching
API Layer
api_routes.py
: REST endpoints with CRUD operations, circular reference validation, and error handling
Frontend Architecture
web/tree_view.js
: Tree view with drag-and-drop, context menus, visual hierarchy indicators, and real-time updatesweb/edit_dialog.js
: Simple editing interface with live preview, organization, drag-and-drop, etc.web/extensions.js
: ComfyUI integration layer for workflow integration
๐ค Contributing
- Fork the repository.
- Create a feature branch.
- Make changes with proper documentation.
- Add tests for new functionality.
- Submit a pull request.