Compare commits

...
7 Commits
Author SHA1 Message Date
THE_BEAST\me ecdf1e0995 add custom Llama path preference option 2025-12-16 13:14:15 -05:00
Francois Beaudry 39575f137c Fix llama.cpp URL in README
Updated the README to correct the URL for llama.cpp.
2025-12-16 09:52:20 -05:00
THE_BEAST\me e993546fa4 Improve error message handling in Prompt Generator 2025-12-16 03:52:14 -05:00
Francois Beaudry ce12566998 Revise README for better readability and organization
Updated README to improve clarity and formatting.
2025-12-16 00:56:38 -05:00
THE_BEAST\me c61dcaad2c - Bumped version to 1.8.0.
- Added support for Qwen3VL Thinking model variants and improved model management.
- Enhanced error handling and console output for better debugging.
- Improved options node for better user experience and functionality.
2025-12-16 00:44:07 -05:00
THE_BEAST\me 1ba2d214f6 Added Better Llama Shutdown logic, should force close it when Comfy closes. Improved system prompts for "Analyze Image with Prompt". Previous one was preventing LLM to be creative. Now uses the models default values by default. Option node can be used to overide them.
Refactor preference management: move API endpoints to model_manager.py and remove in-memory cache from prompt_manager.py
2025-12-15 18:37:07 -05:00
THE_BEAST\me 473d96084c Enhance model management and prompt generation capabilities
- Added support for additional Qwen3VL models in model_manager.py.
- Improved mmproj file path retrieval logic to search for relevant files based on model name components.
- Introduced new functions in prompt_generator.py for better handling of server processes, including cleanup on exit and signal handling.
- Enhanced prompt generation with detailed console output options, including enabling/disabling thinking mode and showing detailed debug information.
- Updated prompt_generator_options.py to allow connecting multiple images for analysis and added options for enabling thinking mode and console output.
- Minor cleanup in prompt_manager.py to remove unnecessary whitespace.
2025-12-15 04:10:10 -05:00
10 changed files with 843 additions and 260 deletions
+54 -16
View File
@@ -1,13 +1,27 @@
# ComfyUI Prompt Manager
A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organizing, generating, and enhancing prompts using local llama.cpp models with vision analysis support.
**A custom [ComfyUI](https://github.com/comfyanonymous/ComfyUI) node for Organizing, Generating or Enhancing prompts.**
(**Llama.cpp needs to be installed and accessible from command prompt.**)
This addon started off as a simple prompt Manager, to help save and retrieve prompts.
But has since evolved to be a complete toolset to help Generate prompts also.
***
Uses an existing install of [llama.cpp](https://github.com/ggerganov/llama.cpp), preventing install conflicts with ComfyUI.
Provides options to automatically download Qwen3 and Qwen3VL models.
Supports prompt enhancing, image analysis, or custom image processing, with up to 5 images at once.
Custom GGUF models can be used if supported by llama.cpp; simply drop them in the models/gguf folder.
Users can set a custom Llama-server path, if not defined in your System Path.
<div align="center">
<figcaption>Simple Prompt Generator Usage</figcaption>
<img src="docs/prompt_manager.png" alt="Prompt Manager">
</div>
<div align="center">
<figcaption>Advanced Prompt Generator Usage</figcaption>
<img src="docs/prompt_manager_advanced.png" alt="Prompt Manager">
</div>
### Key features:
### Prompt Manager:
- **Category Organization**: Create and manage multiple categories to organize your prompts
@@ -22,16 +36,19 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
- **Vision Analysis**: Analyze images with Qwen3VL models to generate detailed descriptions
- **Custom Image Analysis**: Provide your own instructions for image analysis
- **JSON Output**: Optional structured JSON output with scene breakdown
- **Automatic Server Management**: Starts/stops llama.cpp server as needed
- **Smart Model Selection**: Auto-selects appropriate model (vision or text) based on mode
- **Model Preferences**: Set preferred models in ComfyUI Settings for automatic selection
- **Thinking Support**: Support Thinking models to perform deeper generative reasoning.
- **Automatic Server Management**: Starts/stops llama.cpp server as needed, with automatic shut off at exit.
- **Smart Model Selection**: Auto-selects appropriate model (vision or text) based on mode or Thinking mode.
- **Model Preferences**: Set preferred models in ComfyUI preferences for automatic selection.
- **Custom Llama path**: In preferences you can set a custom Llama install Path, if not defined in your System Path.
### Prompt Generator Options
- **Model Selection**: Choose from local models or download Qwen3 (1.7B/4B/8B) and Qwen3VL (4B/8B) from HuggingFace
- **Model Selection**: Choose from local models or download Qwen3, Qwen3VL and Qwen3VL Thinking models from HuggingFace
- **Auto-Download**: Automatically downloads both model and required mmproj files for vision models
- **Context Size**: Adjustable context window (512-32768 tokens)
- **LLM Parameters**: Fine-tune temperature, top_k, top_p, min_p, repeat_penalty
- **Custom Instructions**: Override default system prompt for different enhancement styles
- **LLM Parameters**: Fine-tune temperature, top_k, top_p, min_p, repeat_penalty and context size.
- **Custom Instructions**: Override default system prompt for different enhancement styles.
- **Extra Image Inputs**: Combine up to 5 images to generate your prompt.
- **Console Debugging**: Enable outputing the entire process to the console for debugging purposes.
## Installation
@@ -55,7 +72,6 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
5. If you have them, place your .gguf models in the models/gguf folder. (Create folder if not present)
6. Restart ComfyUI
## Usage
@@ -77,15 +93,19 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
- "Analyze Image" - Generate detailed image descriptions
- "Analyze Image with Prompt" - Analyze images with custom instructions
3. **Connect inputs**: Connect image for vision modes, or just use text for enhancement mode
4. **Output as Json**: Use Format_as_Json to experiment with Json prompts.
5. **Push the LLM**: Use enable_thinking to enable the model to perform deeper generative reasoning before producing the final prompt.
4. **Save memory**: Toggle "stop_server_after" ON to free VRAM after generation
5. **Run Workflow**: Generated prompt displays and can be saved to Prompt Manager
**Advanced Usage**:
1. **Add the Options Node**: Add Node → Prompt Generator Options
2. **Connect Options**: Connect the options node to the Prompt Generator Options input
3. **Select from available models**: Select from models found in your modeld\gguf folder. Qwen models will be available to download.
4. **Adjust settings**: Adjust LLM parameters (temperature, top_k, etc.)
5. **Customize LLM**: Customize the default LLM instructions to modify the responses llama returns.
3. **Analyze multiple images**: Connect up to 4 additional images, for a total of 5.
4. **Select from available models**: Select from models found in your models\gguf folder. Qwen models will be available to download.
5. **Adjust settings**: Adjust LLM parameters (temperature, top_k, etc.)
6. **Customize LLM**: Customize the default LLM instructions to modify the responses llama returns.
7. **Enable Debugging**: Enable complete printout of process to console using show_everything_in_console
**Qwen models found in options**
- Qwen3-1.7B-Q8_0.gguf: Fastest, lowest VRAM (~2GB)
@@ -93,6 +113,8 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
- Qwen3-8B-Q8_0.gguf: Best quality, highest VRAM (~8GB)
- Qwen3VL-4B-Instruct-Q8_0.gguf: Vision model, balanced performance (~5GB VRAM)
- Qwen3VL-8B-Instruct-Q8_0.gguf: Vision model, best quality (~9GB VRAM)
- Qwen3VL-4B-Thinking-Q8_0.gguf: Vision model, Thinking variant, balanced performance (~5GB VRAM)
- Qwen3VL-8B-Thinking-Q8_0.gguf: Vision model, Thinking variant, best quality (~9GB VRAM)
**Model Management**:
- Place gguf files in models/gguf folder
@@ -142,8 +164,24 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
**Problem**: Generation is slow
- **Solution**: Either, Use a smaller quantized model (Q4 instead of Q8) or toggle 'stop_server_after' to quit llama.cpp after generating prompt.
**Problem**: Default Model used is not what I want
- **Solution**: You can set your preferred model in the ComfyUI settings. Simply add its full name for both the VL and base models. Enabling Thinking in the Generator might change what is used.
## Changelog
### Version 1.8.1
- Added option to set a custom Llama path in preferences, for those that have specific installs.
### Version 1.8.0
- Added support for Qwen3VL Thinking model variants, with download options thru the Generator Options node.
- Model manager now searches for relevant `mmproj` files using model-name components for more reliable vision-model linking.
- Detailed console output options (debug logging)
- `enable_thinking` toggle to enable/disable the model's reasoning/thinking mode.
- Options node now accepts multiple images for analysis.
- Better Llama shutdown behavior to force-close the server when Comfy exits.
- Uses model-reported sampling params by default when available; the Options node can override them per-parameter.
- Moved preference API endpoints and cache handling into `model_manager.py` for cleaner management and persistence.
### Version 1.7.0
- Added three-mode prompt generator: "Enhance User Prompt", "Analyze Image", "Analyze Image with Prompt"
- Enhanced vision model workflow with dedicated image analysis modes
@@ -152,7 +190,7 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
- Added automatic model preference management (separate settings for base and vision models)
- Improved model selection with preference fallback to smallest model
- Filtered mmproj files from model selection dropdowns
- All preferences stored in ComfyUI settings for persistence across updates
- Model preferences stored in ComfyUI settings for persistence across updates
### Version 1.6.0
- Added Qwen3VL vision model support for image analysis
@@ -165,8 +203,8 @@ A custom node for [ComfyUI](https://github.com/comfyanonymous/ComfyUI) for organ
- Fixed multiple directory support for model search (gguf + LLM folders)
### Version 1.5.1
- LLM output remains avaiable when use llm is off. So it can be edited
- Improved Caching detection, any change to options will be detected and force a new ouput
- LLM output remains available when use_llm is off, so it can be edited.
- Improved caching detection: any change to options will be detected and force a new output.
- Improved some UI quirks
### Version 1.5.0
+1 -1
View File
@@ -2,7 +2,7 @@
ComfyUI Prompt Manager - A simple custom node for saving and reusing prompts
A prompt management system for ComfyUI with LLM input support
"""
__version__ = "1.5.1"
__version__ = "1.8.1"
__author__ = "François Beaudry"
__license__ = "MIT"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 268 KiB

After

Width:  |  Height:  |  Size: 450 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 KiB

+61 -1
View File
@@ -42,6 +42,25 @@ app.registerExtension({
console.error("[PromptManager] Error saving vision model preference:", error);
}
}
},
{
id: "PromptManager.LlamaPath",
category: ["Prompt Manager", "Llama Preferences", "Custom Llama Path"],
name: "Custom Llama Path",
tooltip: "Path to custom Llama installation (Can leave empty if it's defined in your system Path)",
type: "text",
defaultValue: "",
async onChange(value) {
try {
await fetch("/prompt-manager/save-preference", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ key: "custom_llama_path", value: value })
});
} catch (error) {
console.error("[PromptManager] Error saving Llama path preference:", error);
}
}
}
],
async setup() {
@@ -183,10 +202,51 @@ app.registerExtension({
// Enforce minimum node width
const onResize = nodeType.prototype.onResize;
nodeType.prototype.onResize = function(size) {
size[0] = Math.max(400, size[0]);
size[0] = Math.max(300, size[0]);
return onResize ? onResize.apply(this, arguments) : size;
};
}
// Make the Options node taller/wider by default so the system_prompt area is roomier
if (nodeData.name === "PromptGenOptions") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
// Set a default size (width x height)
try {
this.setSize([400, 420]);
} catch (e) {
// ignore if method unavailable
}
return result;
};
// Enforce sensible minimums when the user resizes the options node
const onResizeOpt = nodeType.prototype.onResize;
nodeType.prototype.onResize = function(size) {
size[0] = Math.max(300, size[0]);
return onResizeOpt ? onResizeOpt.apply(this, arguments) : size;
};
}
// Enforce minimum size for ModelGenerator node (no default size)
if (nodeData.name === "PromptGenerator") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated?.apply(this, arguments);
// Set a default size (width x height)
try {
this.setSize([400, 300]);
} catch (e) {
// ignore if method unavailable
}
return result;
};
const onResizeModel = nodeType.prototype.onResize;
nodeType.prototype.onResize = function(size) {
size[0] = Math.max(300, size[0]);
return onResizeModel ? onResizeModel.apply(this, arguments) : size;
};
}
}
});
+60 -8
View File
@@ -5,11 +5,18 @@ import os
import glob
import json
import folder_paths
import server
from huggingface_hub import HfApi
from tqdm.auto import tqdm
import requests
# Add preference cache and API endpoints for preferences
_preferences_cache = {
"preferred_base_model": "",
"preferred_vision_model": "",
"custom_llama_path": ""
}
# Predefined models - use real filenames as keys
QWEN_MODELS = {
"Qwen3-1.7B-Q8_0.gguf": {
@@ -28,11 +35,41 @@ QWEN_MODELS = {
"Qwen3VL-8B-Instruct-Q8_0.gguf": {
"repo": "Qwen/Qwen3-VL-8B-Instruct-GGUF",
"mmproj": "mmproj-Qwen3VL-8B-Instruct-Q8_0.gguf"
},
"Qwen3VL-4B-Thinking-Q8_0.gguf": {
"repo": "Qwen/Qwen3-VL-4B-Thinking-GGUF",
"mmproj": "mmproj-Qwen3VL-4B-Thinking-Q8_0.gguf"
},
"Qwen3VL-8B-Thinking-Q8_0.gguf": {
"repo": "Qwen/Qwen3-VL-8B-Thinking-GGUF",
"mmproj": "mmproj-Qwen3VL-8B-Thinking-Q8_0.gguf"
}
}
# Preferences are now stored in ComfyUI settings (comfy.settings.json)
# and accessed via the settings API in prompt_manager.py
@server.PromptServer.instance.routes.get("/prompt-manager/load-preferences")
async def load_preferences(request):
"""API endpoint to get cached preferences (set from ComfyUI settings)"""
return server.web.json_response(_preferences_cache)
@server.PromptServer.instance.routes.post("/prompt-manager/save-preference")
async def save_preference(request):
"""API endpoint to update preference cache when settings change"""
try:
data = await request.json()
key = data.get("key")
value = data.get("value", "")
if key not in ["preferred_base_model", "preferred_vision_model", "custom_llama_path"]:
return server.web.json_response({"success": False, "error": "Invalid preference key"})
# Update in-memory cache
_preferences_cache[key] = value
return server.web.json_response({"success": True, "preferences": _preferences_cache})
except Exception as e:
print(f"[Model Manager] Error saving preference: {e}")
return server.web.json_response({"success": False, "error": str(e)}, status=500)
def get_models_directory():
"""Get the path to the primary models directory (ComfyUI/models/gguf) for downloads"""
@@ -136,11 +173,26 @@ def get_mmproj_for_model(model_name):
return None
def get_mmproj_path(model_name):
"""Get the path to the mmproj file for a vision model, if it exists"""
mmproj_name = get_mmproj_for_model(model_name)
if mmproj_name and is_model_local(mmproj_name):
return get_model_path(mmproj_name)
return None
"""Get the path to the mmproj file for a vision model, if it exists
Searches for mmproj files that contain all parts of the model name
"""
# Get all parts of the model name (excluding .gguf)
model_parts = model_name.replace('.gguf', '').split('-')
# Get all local mmproj files
all_dirs = get_all_model_directories()
mmproj_files = []
for models_dir in all_dirs:
if os.path.exists(models_dir):
for f in os.listdir(models_dir):
if f.startswith('mmproj-') and f.endswith('.gguf'):
mmproj_files.append(f)
# Find mmproj that contains all model parts
for mmproj_file in mmproj_files:
mmproj_parts = mmproj_file.replace('mmproj-', '').replace('.gguf', '').split('-')
if all(part in mmproj_parts for part in model_parts):
return get_model_path(mmproj_file)
def download_model(model_name):
"""Download a model from HuggingFace with automatic progress display
+622 -185
View File
File diff suppressed because it is too large Load Diff
+44 -16
View File
@@ -26,12 +26,28 @@ class PromptGenOptions:
"default": available_models[0] if available_models else "",
"tooltip": "Select model to use (local models listed first, then HuggingFace models)"
}),
"image2": ("IMAGE", {
"tooltip": "Connect an image (required for 'Analyze Image' and 'Analyze Image with Prompt' modes)"
}),
"image3": ("IMAGE", {
"tooltip": "Connect an image (required for 'Analyze Image' and 'Analyze Image with Prompt' modes)"
}),
"image4": ("IMAGE", {
"tooltip": "Connect an image (required for 'Analyze Image' and 'Analyze Image with Prompt' modes)"
}),
"image5": ("IMAGE", {
"tooltip": "Connect an image (required for 'Analyze Image' and 'Analyze Image with Prompt' modes)"
}),
"system_prompt": ("STRING", {
"multiline": True,
"default": "",
"placeholder": "Replace LLM Instructions...",
"tooltip": "Custom LLM Instructions (leave empty to use default)\nThe default instructions are designed for generating\ndetailed and imaginative prompts for text-to-image generation."
}),
"use_model_default_sampling": ("BOOLEAN", {
"default": False,
"tooltip": "Use the model's default sampling parameters (overrides temperature, top_p, etc)"
}),
"temperature": ("FLOAT", {
"default": 0.8,
"min": 0.0,
@@ -74,6 +90,10 @@ class PromptGenOptions:
"step": 512,
"tooltip": "Context size (increase for vision models or large prompts)"
}),
"show_everything_in_console": ("BOOLEAN", {
"default": False,
"tooltip": "Print system prompt, user prompt, thinking process, and raw model response to console"
})
}
}
@@ -87,11 +107,12 @@ class PromptGenOptions:
"""Force refresh when models are updated"""
return _last_model_update
def create_options(self, model: str = None,
system_prompt: str = None, temperature: float = None,
def create_options(self, model: str = None, image2=None, image3=None, image4=None, image5=None,
system_prompt: str = None, use_model_default_sampling: bool = None, temperature: float = None,
top_k: int = None, top_p: float = None, min_p: float = None,
repeat_penalty: float = None, context_size: int = None) -> dict:
"""Create options dictionary with model and LLM parameters"""
repeat_penalty: float = None, context_size: int = None,
show_everything_in_console: bool = None) -> dict:
"""Create options dictionary with model, LLM parameters, and extra images"""
options = {}
@@ -123,21 +144,28 @@ class PromptGenOptions:
else:
options["model"] = model
# Add extra images if provided
if image2 is not None:
options["image2"] = image2
if image3 is not None:
options["image3"] = image3
if image4 is not None:
options["image4"] = image4
if image5 is not None:
options["image5"] = image5
# Only include LLM parameters that are provided
if system_prompt and system_prompt.strip():
options["system_prompt"] = system_prompt
if temperature is not None:
options["temperature"] = temperature
if top_p is not None:
options["top_p"] = top_p
if top_k is not None:
options["top_k"] = top_k
if min_p is not None:
options["min_p"] = min_p
if repeat_penalty is not None:
options["repeat_penalty"] = repeat_penalty
if context_size is not None:
options["context_size"] = context_size
options["use_model_default_sampling"] = use_model_default_sampling
options["temperature"] = temperature
options["top_p"] = top_p
options["top_k"] = top_k
options["min_p"] = min_p
options["repeat_penalty"] = repeat_penalty
options["context_size"] = context_size
options["show_everything_in_console"] = show_everything_in_console
return (options,)
-32
View File
@@ -3,11 +3,6 @@ import json
import folder_paths
import server
# Store preferences in memory (ComfyUI settings is the source of truth)
_preferences_cache = {
"preferred_base_model": "",
"preferred_vision_model": ""
}
class PromptManager:
@@ -258,30 +253,3 @@ async def delete_prompt(request):
except Exception as e:
print(f"[PromptManager] Error in delete_prompt API: {e}")
return server.web.json_response({"success": False, "error": str(e)}, status=500)
@server.PromptServer.instance.routes.get("/prompt-manager/load-preferences")
async def load_preferences(request):
"""API endpoint to get cached preferences (set from ComfyUI settings)"""
return server.web.json_response(_preferences_cache)
@server.PromptServer.instance.routes.post("/prompt-manager/save-preference")
async def save_preference(request):
"""API endpoint to update preference cache when settings change"""
try:
data = await request.json()
key = data.get("key")
value = data.get("value", "")
if key not in ["preferred_base_model", "preferred_vision_model"]:
return server.web.json_response({"success": False, "error": "Invalid preference key"})
# Update in-memory cache
_preferences_cache[key] = value
return server.web.json_response({"success": True, "preferences": _preferences_cache})
except Exception as e:
print(f"[PromptManager] Error saving preference: {e}")
return server.web.json_response({"success": False, "error": str(e)}, status=500)
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui-prompt-manager"
description = "Prompt Manager for ComfyUI, with llama.cpp integration for prompt generation and vision analysis. Organize, generate, and save prompts with local LLM support."
version = "1.7.0"
version = "1.8.1"
[project.urls]
Repository = "https://github.com/FranckyB/ComfyUI-Prompt-Manager"