Add Random Prompt Choice

This commit is contained in:
Francesco Bellini 2025-10-07 21:13:19 +02:00
parent 241aeb7c69
commit 89197dce65
2 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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,)