From 4d0f3978f1535134374a8bddf58db9363b565da3 Mon Sep 17 00:00:00 2001 From: DreamFly Date: Sun, 13 Apr 2025 02:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BE=93=E5=85=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 5 +++ nodes/prompt_text.py | 80 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 nodes/prompt_text.py diff --git a/__init__.py b/__init__.py index 33b53bf..83f78f5 100644 --- a/__init__.py +++ b/__init__.py @@ -13,6 +13,7 @@ from .nodes.prompt_combine import CombinePrompt, MultiCombinePrompt from .nodes.prompt_replace import ReplacePrompt, MultiReplacePrompt from .nodes.prompt_custom import CustomPrompt from .nodes.prompt_save import SavePrompt +from .nodes.prompt_text import InputPrompt, RandomLinePrompt from .nodes.prompt_preview import PreviewPrompt @@ -35,6 +36,8 @@ NODE_CLASS_MAPPINGS = { "MultiReplacePrompt": MultiReplacePrompt, "CustomPrompt": CustomPrompt, "SavePrompt": SavePrompt, + "InputPrompt": InputPrompt, + "RandomLinePrompt": RandomLinePrompt, "PreviewPrompt": PreviewPrompt, } @@ -56,6 +59,8 @@ NODE_DISPLAY_NAME_MAPPINGS = { "MultiReplacePrompt": "Multi Replace Prompt", "CustomPrompt": "Custom Prompt", "SavePrompt": "Save Prompt", + "InputPrompt": "Input Prompt", + "RandomLinePrompt": "Random Line Prompt", "PreviewPrompt", "Preview Prompt", } diff --git a/nodes/prompt_text.py b/nodes/prompt_text.py new file mode 100644 index 0000000..ed58d5e --- /dev/null +++ b/nodes/prompt_text.py @@ -0,0 +1,80 @@ +import os + + +# Input Prompt +class InputPrompt: + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "text": ("STRING", { + "default": "", + "multiline": True + }) + } + } + + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) + FUNCTION = "input_prompt" + CATEGORY = "PromptWrapper" + + def input_prompt(self, text=""): + + return (text, ) + + + + +# Random Line Prompt +class RandomLinePrompt: + + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "text": ("STRING", { + "default": "", + "multiline": True, + "tooltip" : "string split is use \\n character." + }), + "seed": ("INT", { + "default": 0, + "min": 0, + "max": 0xFFFFFFFFFFFFFFFF + }) + }, + "optional": { + "input_prompt": ("STRING", {"forceInput": True}), + } + } + + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("text",) + FUNCTION = "random_text" + OUTPUT_NODE = True + CATEGORY = "PromptWrapper" + + def random_text(self, text="", seed=0, input_prompt=""): + + output_texts = [] + if input_prompt != "": + lines = input_prompt.split("\n") + for line in lines: + output_texts.append(line) + + if text != "": + lines = text.split("\n") + for line in lines: + output_texts.append(line) + + output_prompt = "" + line_count = len(output_texts) + if line_count > 0: + line_index = seed % line_count + output_prompt = output_texts[line_index] + + return (output_prompt, ) \ No newline at end of file