Files
ComfyAssets-ComfyUI-KikoTools/kikotools/tools/xyz_helpers/text_encode_sampler_params/node.py
T
Vito Sansevero 5485aa8c19 feat(xyz-helpers): add ComfyUI_essentials nodes adaptation
BREAKING CHANGE: Node categories now use emoji-based organization

Add 6 new xyz-helper nodes adapted from comfyui-essentials-nodes:
- FluxSamplerParams: FLUX-optimized parameter generator with batch support
- LoRAFolderBatch: Batch process multiple LoRAs from folders
- PlotParameters: Visualize parameter effects with graphs
- SamplerSelectHelper: Intelligent sampler selection with recommendations
- SchedulerSelectHelper: Optimal scheduler selection for samplers
- TextEncodeSamplerParams: Combined text encoding and parameter management

Changes:
- Port and enhance nodes from comfyui-essentials (now in maintenance mode)
- Add comprehensive documentation with attribution to original author (cubiq)
- Create example workflows for xyz-helpers tools
- Update all node categories to use emoji-based organization
- Fix all unit tests to pass with new category system
- Update README with xyz-helpers section and attribution

Attribution: xyz-helpers adapted from github.com/cubiq/ComfyUI_essentials

All tests passing (318 pass, 2 skip)
2025-08-07 05:41:23 -07:00

85 lines
2.6 KiB
Python

"""Text Encode for Sampler Params node for ComfyUI."""
from typing import Tuple, Any
from ....base.base_node import ComfyAssetsBaseNode
from .logic import (
split_prompts,
encode_prompts,
create_sampler_params_conditioning,
validate_prompt_format,
)
class TextEncodeSamplerParamsNode(ComfyAssetsBaseNode):
"""
Text Encode for Sampler Params node.
Splits multi-line text by separators (---, ***, ===, ~~~) and encodes
each part separately. Returns a special conditioning format suitable
for batch processing and XYZ plot generation.
"""
@classmethod
def INPUT_TYPES(cls):
"""Define the input types for the ComfyUI node."""
return {
"required": {
"text": (
"STRING",
{
"multiline": True,
"dynamicPrompts": True,
"default": "Separate prompts with at least three dashes\n---\nLike so",
"tooltip": "Multi-line text with --- separators between prompts",
},
),
"clip": ("CLIP", {"tooltip": "CLIP model for text encoding"}),
}
}
RETURN_TYPES = ("CONDITIONING",)
RETURN_NAMES = ("conditioning",)
FUNCTION = "encode_prompts"
CATEGORY = "ComfyAssets/🧰 xyz-helpers"
def encode_prompts(self, text: str, clip: Any) -> Tuple[Any]:
"""
Split and encode multiple prompts for batch processing.
Args:
text: Multi-line text with separators
clip: CLIP encoder model
Returns:
Tuple containing conditioning dictionary
"""
try:
if not validate_prompt_format(text):
self.handle_error("Invalid prompt format")
prompts = split_prompts(text)
if not prompts:
self.log_info("No prompts found in text")
return ({"text": [], "encoded": []},)
self.log_info(f"Processing {len(prompts)} prompts")
encoded = encode_prompts(prompts, clip)
if not encoded:
self.handle_error("Failed to encode any prompts")
conditioning = create_sampler_params_conditioning(prompts, encoded)
self.log_info(
f"Successfully encoded {len(encoded)} prompts "
f"(avg {sum(len(p) for p in prompts) // len(prompts)} chars)"
)
return (conditioning,)
except Exception as e:
self.handle_error(f"Error processing prompts: {str(e)}", e)
return ({"text": [], "encoded": []},)