Skip to content

Commit

Permalink
Automatically add forceInput for template types
Browse files Browse the repository at this point in the history
  • Loading branch information
guill committed Oct 20, 2024
1 parent a063468 commit d7f0a4a
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions comfy_execution/node_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#
# Variadic Input - Different Types
# If you want to have a variadic input with a dynamic type, you can combine the two. For example, if you have an input named "input#COUNT" with the type "<FOO#COUNT>", each socket for the input can have a different type. (Internally, this is equivalent to making the type <FOO1> where 1 is the index of this input.)
#
# Restrictions
# - All dynamic inputs must have `"forceInput": True` due to frontend reasons that will hopefully be resolved before merging.

def TemplateTypeSupport():
def decorator(cls):
Expand All @@ -35,7 +32,16 @@ def new_input_types(cls):
if category not in old_types:
continue
for key, value in old_types[category].items():
new_types[category][replace_variadic_suffix(key, 1)] = (template_to_type(value[0]),) + value[1:]
input_name = replace_variadic_suffix(key, 1)
input_type = template_to_type(value[0])
if len(value) == 1:
extra_info = {}
else:
extra_info = value[1]
if input_name != key or input_type != value[0]:
# TODO - Fix front-end to handle widgets and remove this
extra_info["forceInput"] = True
new_types[category][input_name] = (input_type,extra_info)
return new_types
setattr(cls, "INPUT_TYPES", classmethod(new_input_types))
old_outputs = getattr(cls, "RETURN_TYPES")
Expand Down Expand Up @@ -77,7 +83,14 @@ def resolve_dynamic_types(cls, input_types, output_types, entangled_types):
input_type = value[0]
if isinstance(input_type, str):
input_type = replace_variadic_suffix(input_type, i)
variadic_inputs[category][replace_variadic_suffix(key, i)] = (input_type,value[1])
if len(value) == 1:
extra_info = {}
else:
extra_info = value[1]
if input_type != value[0]:
# TODO - Fix front-end to handle widgets and remove this
extra_info["forceInput"] = True
variadic_inputs[category][replace_variadic_suffix(key, i)] = (input_type,extra_info)

# Step 3 - Resolve template arguments
resolved = {}
Expand All @@ -103,7 +116,15 @@ def resolve_dynamic_types(cls, input_types, output_types, entangled_types):
}
for category in ["required", "optional"]:
for key, value in variadic_inputs[category].items():
final_inputs[category][key] = (template_to_type(value[0], resolved),) + value[1:]
if len(value) == 1:
extra_info = {}
else:
extra_info = value[1]
resolved_type = template_to_type(value[0], resolved)
if resolved_type != value[0]:
# TODO - Fix front-end to handle widgets and remove this
extra_info["forceInput"] = True
final_inputs[category][key] = (resolved_type,extra_info)
outputs = (template_to_type(x, resolved) for x in old_outputs)
return {
"input": final_inputs,
Expand Down

0 comments on commit d7f0a4a

Please sign in to comment.