-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmart_prompt_controller.py
More file actions
97 lines (82 loc) · 3.11 KB
/
smart_prompt_controller.py
File metadata and controls
97 lines (82 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class SmartPromptController:
"""
Craftopia — Smart Prompt Controller 🎛️
Cycles through up to 4 prompt lists using a single incrementing counter.
Counts lines automatically and outputs the selected prompt + list number.
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"counter": ("INT", {
"default": 1,
"min": 1,
"max": 99999,
"step": 1,
"display": "number",
"control_after_generate": "increment",
}),
},
"optional": {
"prompt_list_1": ("STRING", {"forceInput": True}),
"prompt_list_2": ("STRING", {"forceInput": True}),
"prompt_list_3": ("STRING", {"forceInput": True}),
"prompt_list_4": ("STRING", {"forceInput": True}),
}
}
RETURN_TYPES = ("STRING", "INT")
RETURN_NAMES = ("prompt", "list_index")
FUNCTION = "control"
CATEGORY = "CraftKit"
OUTPUT_NODE = True
def _get_lines(self, text):
"""Return list of non-empty lines from a text block."""
if not text:
return []
if isinstance(text, list):
text = text[0] if text else ""
return [l for l in str(text).splitlines() if l.strip()]
def control(self, counter, prompt_list_1="", prompt_list_2="",
prompt_list_3="", prompt_list_4=""):
raw = [prompt_list_1, prompt_list_2, prompt_list_3, prompt_list_4]
# Collect active lists: (list_index, [lines])
active = []
for i, text in enumerate(raw):
lines = self._get_lines(text)
if lines:
active.append((i, lines))
total_all = sum(len(lines) for _, lines in active)
if total_all == 0:
return {"ui": {"text": ["no prompts connected"]},
"result": ("", 0)}
# Map counter position to list + line
position = (counter - 1) % total_all
cumulative = 0
selected_list_index = 0
selected_line_index = 0
selected_prompt = ""
for list_idx, lines in active:
if position < cumulative + len(lines):
selected_list_index = list_idx
selected_line_index = position - cumulative
selected_prompt = lines[selected_line_index]
break
cumulative += len(lines)
# Label: "List 1 — 4/5 | total: 8"
list_number = selected_list_index + 1
list_total = len(self._get_lines(raw[selected_list_index]))
prompt_display = selected_line_index + 1
label = f"List {list_number} \u2014 {prompt_display}/{list_total} | total: {total_all}"
return {
"ui": {"text": [label]},
"result": (
selected_prompt,
list_number,
)
}
NODE_CLASS_MAPPINGS = {
"SmartPromptController": SmartPromptController,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"SmartPromptController": "Smart Prompt Controller \ud83c\udf9b\ufe0f",
}