Skip to content

Commit 8a8dc96

Browse files
committed
fix to make ckpt_name compatible with loader nodes
1 parent 90062ff commit 8a8dc96

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "ComfyUI-Prompt-Companion"
7-
version = "0.0.5"
7+
version = "0.0.6"
88
description = "A node that lets you save and reuse parts of prompts (embeddings, quality keywords, and so on.)"
99
authors = [
1010
{name = "John Cantu", email = "jfcantu@gmail.com"}

src/prompt_companion_node.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ class PromptCompanion:
116116
- Group (Automatic): Apply groups based on trigger word matching
117117
"""
118118

119-
# ComfyUI node metadata
120-
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING", "STRING", "PROMPT_ADDITION")
119+
# ComfyUI node metadata - use same type as checkpoint input for compatibility
120+
RETURN_TYPES = (folder_paths.get_filename_list("checkpoints") if folder_paths else ["test_model.safetensors"], "STRING", "STRING", "STRING", "STRING", "PROMPT_ADDITION")
121121
RETURN_NAMES = ("ckpt_name", "positive_combined_prompt", "negative_combined_prompt",
122122
"positive_addition", "negative_addition", "prompt_addition")
123+
OUTPUT_TOOLTIPS = ("Checkpoint filename compatible with Load Checkpoint nodes",
124+
"Combined positive prompt with additions applied",
125+
"Combined negative prompt with additions applied",
126+
"The positive prompt addition text that was applied",
127+
"The negative prompt addition text that was applied",
128+
"Prompt addition data that can be connected to other nodes")
123129
FUNCTION = "combine_prompts"
124130
OUTPUT_NODE = True
125131
CATEGORY = "jfc"
@@ -265,9 +271,12 @@ def combine_prompts(
265271
Returns:
266272
Tuple of (ckpt_name, positive_combined, negative_combined, positive_addition, negative_addition, prompt_addition)
267273
"""
274+
# Validate and ensure ckpt_name is compatible with Load Checkpoint
275+
validated_ckpt_name = self._validate_checkpoint_name(ckpt_name)
276+
268277
# Always return ckpt_name first
269278
if not enable_addition:
270-
return (ckpt_name, positive_prompt, negative_prompt, "", "", PromptAdditionInput("", ""))
279+
return (validated_ckpt_name, positive_prompt, negative_prompt, "", "", PromptAdditionInput("", ""))
271280

272281
# Calculate addition values based on type
273282
calculated_positive_addition = ""
@@ -310,7 +319,7 @@ def combine_prompts(
310319
)
311320

312321
return (
313-
ckpt_name,
322+
validated_ckpt_name,
314323
final_positive_combined,
315324
final_negative_combined,
316325
calculated_positive_addition,
@@ -482,6 +491,35 @@ def _combine_prompts_with_additions(
482491

483492
return final_positive, final_negative
484493

494+
def _validate_checkpoint_name(self, ckpt_name: str) -> str:
495+
"""
496+
Validate that the checkpoint name is in the available checkpoints list.
497+
This ensures compatibility with Load Checkpoint nodes.
498+
499+
Args:
500+
ckpt_name: The checkpoint name to validate
501+
502+
Returns:
503+
The validated checkpoint name, or the first available if invalid
504+
"""
505+
if not folder_paths:
506+
# Fallback for testing environments
507+
return ckpt_name or "test_model.safetensors"
508+
509+
available_checkpoints = folder_paths.get_filename_list("checkpoints")
510+
511+
if not available_checkpoints:
512+
# No checkpoints available, return as-is
513+
return ckpt_name
514+
515+
if ckpt_name in available_checkpoints:
516+
# Valid checkpoint name
517+
return ckpt_name
518+
else:
519+
# Invalid checkpoint name, return the first available one
520+
print(f"[ComfyUI-Prompt-Companion] Warning: '{ckpt_name}' not found in available checkpoints. Using '{available_checkpoints[0]}' instead.")
521+
return available_checkpoints[0]
522+
485523

486524
# Node registration mapping
487525
NODE_CLASS_MAPPINGS = {

0 commit comments

Comments
 (0)