mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-22 13:42:12 -03:00
Remove direct imports of IO type constants from comfy.comfy_types and replace them with string literals "STRING" in input type definitions and return types. This improves code portability and reduces dependency on external type definitions. Changes made across multiple files: - Remove `from comfy.comfy_types import IO` imports - Replace `IO.STRING` with "STRING" in INPUT_TYPES and RETURN_TYPES - Move CLIPTextEncode import to function scope in prompt.py for better dependency management This refactor maintains the same functionality while making the code more self-contained and reducing external dependencies.
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
from typing import Any, Optional
|
|
|
|
class PromptLoraManager:
|
|
"""Encodes text (and optional trigger words) into CLIP conditioning."""
|
|
|
|
NAME = "Prompt (LoraManager)"
|
|
CATEGORY = "Lora Manager/conditioning"
|
|
DESCRIPTION = (
|
|
"Encodes a text prompt using a CLIP model into an embedding that can be used "
|
|
"to guide the diffusion model towards generating specific images."
|
|
)
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"text": (
|
|
'STRING',
|
|
{
|
|
"multiline": True,
|
|
"pysssss.autocomplete": False,
|
|
"dynamicPrompts": True,
|
|
"tooltip": "The text to be encoded.",
|
|
},
|
|
),
|
|
"clip": (
|
|
'CLIP',
|
|
{"tooltip": "The CLIP model used for encoding the text."},
|
|
),
|
|
},
|
|
"optional": {
|
|
"trigger_words": (
|
|
'STRING',
|
|
{
|
|
"forceInput": True,
|
|
"tooltip": (
|
|
"Optional trigger words to prepend to the text before "
|
|
"encoding."
|
|
)
|
|
},
|
|
)
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ('CONDITIONING', 'STRING',)
|
|
RETURN_NAMES = ('CONDITIONING', 'PROMPT',)
|
|
OUTPUT_TOOLTIPS = (
|
|
"A conditioning containing the embedded text used to guide the diffusion model.",
|
|
)
|
|
FUNCTION = "encode"
|
|
|
|
def encode(self, text: str, clip: Any, trigger_words: Optional[str] = None):
|
|
prompt = text
|
|
if trigger_words:
|
|
prompt = ", ".join([trigger_words, text])
|
|
|
|
from nodes import CLIPTextEncode # type: ignore
|
|
conditioning = CLIPTextEncode().encode(clip, prompt)[0]
|
|
return (conditioning, prompt,) |