Compare commits

..
2 Commits
Author SHA1 Message Date
THE_BEAST\me 9f70a8634a Version 1.1.0 - Added LLM input toggle feature 2025-11-28 17:58:31 -05:00
THE_BEAST\me 5d0ea866ab Simplified readme 2025-11-28 16:53:56 -05:00
6 changed files with 139 additions and 108 deletions
+26 -32
View File
@@ -10,7 +10,7 @@ A simple custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) th
- **Category Organization**: Create and manage multiple categories to organize your prompts (e.g., Character, Style, Environment, Lighting, Mood)
- **Save & Load Prompts**: Quickly save and recall your favorite prompts with custom names
- **LLM Integration**: Connect text outputs from other nodes (like LLM generators) and save them directly
- **LLM Input Toggle**: Connect text outputs from other nodes (like LLM generators) and toggle between using them or your internal prompts
- **Direct Editing**: Edit prompts directly in the node or select from your saved library
- **Persistent Storage**: All prompts are saved in your ComfyUI user folder and persist across sessions
- **Pre-loaded Templates**: Comes with example prompts across various categories
@@ -66,19 +66,21 @@ A simple custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) th
2. Click the **"Del Prompt"** button
3. Confirm the deletion
### Working with LLM Outputs
### Using LLM Input Toggle
You can capture and save outputs from LLM nodes:
The node includes a toggle to switch between internal prompts and external LLM inputs:
1. Connect an LLM output (or any text output) to the **"text"** input of the Prompt Manager node
2. Run your workflow - the generated text will appear in the prompt field
3. Click **"Save Prompt"** to save the LLM-generated text to your library
4. Give it a descriptive name for future use
1. Connect an LLM output (or any text output) to the **"llm_input"** connector
2. Click the **"use llm input"** toggle to switch it ON
3. The prompt field will display the connected text (grayed out)
4. Run your workflow - the node will output the LLM text
5. Click **"Save Prompt"** to save the LLM-generated text to your library
6. Toggle OFF to switch back to your internal prompts
This is perfect for:
- Saving interesting prompts generated by LLMs
- Building a library of AI-generated variations
- Quickly iterating and saving the best results
**Notes:**
- The toggle only works when something is connected to `llm_input`
- When toggled ON, the text field becomes read-only and shows the external input
- When toggled OFF, it reverts to your selected internal prompt
## File Structure
@@ -98,25 +100,17 @@ Prompts are stored in:
```
ComfyUI/user/default/prompt_manager.json
```
The file is automatically created on first use, copying from `default_prompts.json`.
The file is automatically created on first use, copying from `default_prompts.json`. You can:
You can:
- Back up this file to save your prompt library
- Share it with others
- Edit it directly (with caution)
## Default Categories
## Default Prompts
The node comes pre-loaded with example prompts in the following categories:
- **Character**: Fantasy warriors, sci-fi explorers, medieval knights, etc.
- **Style**: Cinematic, oil painting, watercolor, photorealistic, etc.
- **Environment**: Forests, cyberpunk cities, space stations, ancient temples, etc.
- **Lighting**: Golden hour, Rembrandt lighting, neon atmosphere, moonlight, etc.
- **Composition**: Dynamic action, minimalist zen, panoramic vistas, etc.
- **Mood**: Dark and ominous, peaceful, energetic, melancholic, etc.
- **Illustrious**: Anime-style character prompts and scene descriptions
Feel free to modify or delete these to suit your needs!
The node comes pre-loaded with example prompts.
These were added for testing purposes, feel free to modify or delete them to suit your needs!
## Tips & Tricks
@@ -125,11 +119,6 @@ Feel free to modify or delete these to suit your needs!
- Use descriptive names for your prompts to find them easily later
- Regularly backup your `prompt_manager.json` file
### LLM Integration
- Connect multiple Prompt Manager nodes to capture different LLM variations
- Use one node to store "seeds" and another for "final results"
- Combine with LLM nodes to build an iterative prompt refinement workflow
### Editing Prompts
- You can edit prompts directly in the text field even when loaded from the library
- Changes are not saved automatically - click "Save Prompt" to update
@@ -146,11 +135,16 @@ Feel free to modify or delete these to suit your needs!
**Problem**: Can't see LLM output in the node
- **Solution**: Make sure the LLM output is connected to the "text" input and run the workflow.
**Problem**: Node appears too small
- **Solution**: Resize the node by dragging the bottom-right corner. The node will maintain its size in your workflow.
## Changelog
### Version 1.1.0
- Added LLM input toggle for easy switching between internal and external text sources
- Dedicated `llm_input` connector for external text
- Toggle prevents activation when no connection is present
- Text field becomes read-only when using external input
- Auto-reverts to internal prompt when toggle is turned off
- Fixed reload bug where toggle state wasn't applied on page load
### Version 1.0.1
- Initial release
- Category management
+2 -1
View File
@@ -1,7 +1,8 @@
"""
ComfyUI Prompt Manager - A simple custom node for saving and reusing prompts
A prompt management system for ComfyUI with LLM input support
"""
__version__ = "1.0.1"
__version__ = "1.1.0"
__author__ = "François Beaudry"
__license__ = "MIT"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 66 KiB

+95 -69
View File
@@ -28,11 +28,27 @@ app.registerExtension({
promptNameWidget.label = "name";
}
// Listen for text updates from backend (when connected inputs change)
const useExternalWidget = this.widgets.find(w => w.name === "use_external");
if (useExternalWidget) {
useExternalWidget.label = "use llm input";
}
// Listen for text updates from backend (when connected inputs change or toggle changes)
api.addEventListener("prompt-manager-update-text", (event) => {
if (String(event.detail.node_id) === String(this.id)) {
if (promptTextWidget) {
promptTextWidget.value = event.detail.prompt;
const useExternal = event.detail.use_external || false;
const llmInput = event.detail.llm_input || "";
if (useExternal && llmInput) {
// When using external, display the LLM input text (grayed out)
promptTextWidget.value = llmInput;
promptTextWidget.disabled = true;
} else {
// When using internal, enable the widget
promptTextWidget.disabled = false;
}
this.serialize_widgets = true;
app.graph.setDirtyCanvas(true, true);
}
@@ -44,7 +60,7 @@ app.registerExtension({
addButtonBar(node);
setupCategoryChangeHandler(node);
filterPromptDropdown(node);
setupInputConnectionHandler(node);
setupUseExternalToggleHandler(node);
// After buttons are added, ensure height is sufficient
setTimeout(() => {
@@ -76,7 +92,7 @@ app.registerExtension({
if (!node.buttonBarAttached) {
addButtonBar(node);
setupCategoryChangeHandler(node);
setupInputConnectionHandler(node);
setupUseExternalToggleHandler(node);
}
});
}, 100);
@@ -231,15 +247,10 @@ function setupCategoryChangeHandler(node) {
const categoryWidget = node.widgets.find(w => w.name === "category");
const promptWidget = node.widgets.find(w => w.name === "name");
const textWidget = node.widgets.find(w => w.name === "text");
const useExternalWidget = node.widgets.find(w => w.name === "use_external");
if (!categoryWidget || !promptWidget || !textWidget) return;
// Check if text input is connected from another node
const isTextInputConnected = () => {
const promptTextInput = node.inputs?.find(inp => inp.name === "text");
return promptTextInput && promptTextInput.link != null;
};
const originalCallback = categoryWidget.callback;
// Update prompt dropdown when category changes
@@ -255,14 +266,15 @@ function setupCategoryChangeHandler(node) {
if (promptNames.length > 0) {
promptWidget.value = promptNames[0];
// Only update text widget if not connected to another node
if (!isTextInputConnected()) {
// Only update text widget if not using external
const useExternal = useExternalWidget ? useExternalWidget.value : false;
if (!useExternal) {
const promptData = node.prompts[category][promptNames[0]];
textWidget.value = promptData?.prompt || "";
}
} else {
promptWidget.value = "";
if (!isTextInputConnected()) {
if (!useExternal) {
textWidget.value = "";
}
}
@@ -280,8 +292,9 @@ function setupCategoryChangeHandler(node) {
originalPromptCallback.apply(this, arguments);
}
// Only update text if not connected to another node
if (!isTextInputConnected()) {
// Only update text if not using external
const useExternal = useExternalWidget ? useExternalWidget.value : false;
if (!useExternal) {
const category = categoryWidget.value;
if (node.prompts && node.prompts[category] && node.prompts[category][value]) {
const promptData = node.prompts[category][value];
@@ -325,70 +338,83 @@ function setupCategoryChangeHandler(node) {
promptWidget.options._values = promptWidget.options.values || [];
}
function setupInputConnectionHandler(node) {
// Handle displaying value from connected input nodes
function setupUseExternalToggleHandler(node) {
const textWidget = node.widgets?.find(w => w.name === "text");
if (!textWidget) return;
const useExternalWidget = node.widgets?.find(w => w.name === "use_external");
const categoryWidget = node.widgets?.find(w => w.name === "category");
const promptWidget = node.widgets?.find(w => w.name === "name");
if (!textWidget || !useExternalWidget) return;
const originalGetInputOrProperty = node.getInputOrProperty;
if (originalGetInputOrProperty) {
node.getInputOrProperty = function(name) {
const value = originalGetInputOrProperty.apply(this, arguments);
// Apply initial state on load/reload
const applyToggleState = (value) => {
const llmInputConnection = node.inputs?.find(inp => inp.name === "llm_input");
const isLlmConnected = llmInputConnection && llmInputConnection.link != null;
if (name === "text" && value !== undefined) {
textWidget.value = value;
}
return value;
};
}
const graphCanvas = app.graph;
if (graphCanvas) {
const originalBeforeChange = graphCanvas.beforeChange;
graphCanvas.beforeChange = function() {
if (originalBeforeChange) {
originalBeforeChange.apply(this, arguments);
}
const promptTextInput = node.inputs?.find(inp => inp.name === "text");
if (promptTextInput && promptTextInput.link != null) {
const link = graphCanvas.links[promptTextInput.link];
if (link) {
const originNode = graphCanvas.getNodeById(link.origin_id);
if (originNode) {
const outputValue = originNode.getOutputData?.(link.origin_slot);
if (outputValue !== undefined) {
textWidget.value = outputValue;
}
}
}
}
};
}
const api = app.api;
if (api) {
const originalQueuePrompt = api.queuePrompt;
api.queuePrompt = async function(number, workflow) {
const promptTextInput = node.inputs?.find(inp => inp.name === "text");
if (promptTextInput && promptTextInput.link != null) {
const graph = app.graph;
const link = graph.links[promptTextInput.link];
if (link) {
const originNode = graph.getNodeById(link.origin_id);
if (originNode && originNode.widgets) {
const outputWidget = originNode.widgets.find(w => w.name === link.origin_slot || w.name === "text" || w.name === "STRING");
if (value && isLlmConnected) {
// Using LLM and it's connected - disable text widget and show LLM value
const graph = app.graph;
const link = graph.links[llmInputConnection.link];
if (link) {
const originNode = graph.getNodeById(link.origin_id);
if (originNode) {
// Try to get the output value from the origin node
const outputData = originNode.getOutputData?.(link.origin_slot);
if (outputData !== undefined) {
textWidget.value = outputData;
} else if (originNode.widgets) {
// Fallback: try to find widget with matching output
const outputWidget = originNode.widgets.find(w => w.name === "text" || w.name === "STRING");
if (outputWidget) {
textWidget.value = outputWidget.value;
}
}
}
}
textWidget.disabled = true;
} else {
// Using internal text - enable widget and revert to selected prompt
textWidget.disabled = false;
// Revert to the currently selected prompt from the node's prompt library
if (categoryWidget && promptWidget && node.prompts) {
const category = categoryWidget.value;
const promptName = promptWidget.value;
if (node.prompts[category] && node.prompts[category][promptName]) {
const promptData = node.prompts[category][promptName];
textWidget.value = promptData?.prompt || "";
}
}
}
};
return originalQueuePrompt.apply(this, arguments);
};
}
// Apply initial state when the handler is set up
applyToggleState(useExternalWidget.value);
const originalCallback = useExternalWidget.callback;
useExternalWidget.callback = function(value) {
// Check if llm_input is connected
const llmInputConnection = node.inputs?.find(inp => inp.name === "llm_input");
const isLlmConnected = llmInputConnection && llmInputConnection.link != null;
// Prevent turning on if nothing is connected
if (value && !isLlmConnected) {
useExternalWidget.value = false;
node.serialize_widgets = true;
app.graph.setDirtyCanvas(true, true);
return;
}
if (originalCallback) {
originalCallback.apply(this, arguments);
}
applyToggleState(value);
node.serialize_widgets = true;
app.graph.setDirtyCanvas(true, true);
};
}
function createButton(text, callback) {
+15 -5
View File
@@ -32,9 +32,11 @@ class PromptManagerNode:
"required": {
"category": (categories, {"default": first_category}),
"name": (all_prompts_list, {"default": first_prompt}),
"use_external": ("BOOLEAN", {"default": False, "label_on": "on", "label_off": "off", "tooltip": "Toggle to use LLM input instead of internal text"}),
"text": ("STRING", {"multiline": True, "default": first_prompt_text, "placeholder": "Enter prompt text", "dynamicPrompts": False, "tooltip": "Enter prompt text directly"}),
},
"optional": {
"text": ("STRING", {"multiline": True, "default": first_prompt_text, "placeholder": "Enter prompt text or connect input", "dynamicPrompts": False, "forceInput": False, "tooltip": "Enter prompt text directly or connect from another node"}),
"llm_input": ("STRING", {"multiline": True, "forceInput": True, "tooltip": "Connect LLM text input here"}),
},
"hidden": {
"unique_id": "UNIQUE_ID",
@@ -103,16 +105,24 @@ class PromptManagerNode:
except Exception as e:
print(f"[PromptManager] Error saving prompts: {e}")
def get_prompt(self, category, name, text="", unique_id=None):
"""Return the current text in the text field and broadcast update"""
def get_prompt(self, category, name, use_external, text="", llm_input="", unique_id=None):
"""Return the appropriate text based on use_external toggle and broadcast update"""
# Choose which text to use based on the toggle
if use_external and llm_input:
output_text = llm_input
else:
output_text = text
# Broadcast the current prompt text to the frontend
if unique_id is not None:
server.PromptServer.instance.send_sync("prompt-manager-update-text", {
"node_id": unique_id,
"prompt": text
"prompt": output_text,
"use_external": use_external,
"llm_input": llm_input if use_external else ""
})
return (text,)
return (output_text,)
@server.PromptServer.instance.routes.get("/prompt-manager/get-prompts")
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-prompt-manager"
description = "A simple custom node for ComfyUI that allows you to save and reuse prompts, organized into different categories"
version = "1.0.1"
version = "1.1.0"
[project.urls]
Repository = "https://github.com/FranckyB/ComfyUI-Prompt-Manager"