From 89197dce65abeef97a6102e3d00df65e3964e4b4 Mon Sep 17 00:00:00 2001 From: Francesco Bellini Date: Tue, 7 Oct 2025 21:13:19 +0200 Subject: [PATCH] Add Random Prompt Choice --- __init__.py | 2 ++ nodes/DOC_RandomPromptChoice.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 nodes/DOC_RandomPromptChoice.py diff --git a/__init__.py b/__init__.py index 0c7fbe1..518ee89 100644 --- a/__init__.py +++ b/__init__.py @@ -1,10 +1,12 @@ from .nodes.DOC_SaveImageAndAddToHistory import DOC_SaveImageAndAddToHistory +from .nodes.DOC_RandomPromptChoice import DOC_RandomPromptChoice # A dictionary that contains all nodes you want to export with their names # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "DOC_SaveImageAndAddToHistory": DOC_SaveImageAndAddToHistory, + "DOC_RandomPromptChoice": DOC_RandomPromptChoice, } # This magic will use a property DISPLAY_NAME on each node to get the display name of the node for the UI diff --git a/nodes/DOC_RandomPromptChoice.py b/nodes/DOC_RandomPromptChoice.py new file mode 100644 index 0000000..fbd1abb --- /dev/null +++ b/nodes/DOC_RandomPromptChoice.py @@ -0,0 +1,28 @@ +import random + +class DOC_RandomPromptChoice: + def __init__(self): + self.type = "text" + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + **{f"prompt_{i+1}": ("STRING", {"default": "", "tooltip": f"Prompt {i+1}"}) for i in range(20)} + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("selected_prompt",) + FUNCTION = "choose_random_prompt" + CATEGORY = "DOC Utils" + DISPLAY_NAME = "Random Prompt Choice" + + def choose_random_prompt(self, **kwargs): + prompts = [v for v in kwargs.values() if v.strip()] + if not prompts: + return ("",) + choice = random.choice(prompts) + idx = prompts.index(choice) + 1 + print(f"[DOC_RandomPromptChoice] Scelta #{idx}: '{choice[:20]}'") + return (choice,)