mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-24 13:20:19 +08:00
implement optional
This commit is contained in:
parent
dd095efc2c
commit
a3b16a6edc
84
execution.py
84
execution.py
@ -207,45 +207,55 @@ def validate_inputs(prompt, item):
|
|||||||
obj_class = nodes.NODE_CLASS_MAPPINGS[class_type]
|
obj_class = nodes.NODE_CLASS_MAPPINGS[class_type]
|
||||||
|
|
||||||
class_inputs = obj_class.INPUT_TYPES()
|
class_inputs = obj_class.INPUT_TYPES()
|
||||||
required_inputs = class_inputs['required']
|
|
||||||
for x in required_inputs:
|
def validate(current_inputs, is_optional=False):
|
||||||
if x not in inputs:
|
for x in current_inputs:
|
||||||
return (False, "Required input is missing. {}, {}".format(class_type, x))
|
if x not in inputs:
|
||||||
val = inputs[x]
|
if is_optional:
|
||||||
info = required_inputs[x]
|
return (True, "")
|
||||||
type_input = info[0]
|
else:
|
||||||
if isinstance(val, list):
|
return (False, "Required input is missing. {}, {}".format(class_type, x))
|
||||||
if len(val) != 2:
|
val = inputs[x]
|
||||||
return (False, "Bad Input. {}, {}".format(class_type, x))
|
info = current_inputs[x]
|
||||||
o_id = val[0]
|
type_input = info[0]
|
||||||
o_class_type = prompt[o_id]['class_type']
|
if isinstance(val, list):
|
||||||
r = nodes.NODE_CLASS_MAPPINGS[o_class_type].RETURN_TYPES
|
if len(val) != 2:
|
||||||
if r[val[1]] != type_input:
|
return (False, "Bad Input. {}, {}".format(class_type, x))
|
||||||
return (False, "Return type mismatch. {}, {}, {} != {}".format(class_type, x, r[val[1]], type_input))
|
o_id = val[0]
|
||||||
r = validate_inputs(prompt, o_id)
|
o_class_type = prompt[o_id]['class_type']
|
||||||
if r[0] == False:
|
r = nodes.NODE_CLASS_MAPPINGS[o_class_type].RETURN_TYPES
|
||||||
return r
|
if r[val[1]] != type_input:
|
||||||
else:
|
return (False, "Return type mismatch. {}, {}, {} != {}".format(class_type, x, r[val[1]], type_input))
|
||||||
if type_input == "INT":
|
r = validate_inputs(prompt, o_id)
|
||||||
val = int(val)
|
if r[0] == False:
|
||||||
inputs[x] = val
|
return r
|
||||||
if type_input == "FLOAT":
|
else:
|
||||||
val = float(val)
|
if type_input == "INT":
|
||||||
inputs[x] = val
|
val = int(val)
|
||||||
if type_input == "STRING":
|
inputs[x] = val
|
||||||
val = str(val)
|
if type_input == "FLOAT":
|
||||||
inputs[x] = val
|
val = float(val)
|
||||||
|
inputs[x] = val
|
||||||
|
if type_input == "STRING":
|
||||||
|
val = str(val)
|
||||||
|
inputs[x] = val
|
||||||
|
|
||||||
if len(info) > 1:
|
if len(info) > 1:
|
||||||
if "min" in info[1] and val < info[1]["min"]:
|
if "min" in info[1] and val < info[1]["min"]:
|
||||||
return (False, "Value smaller than min. {}, {}".format(class_type, x))
|
return (False, "Value smaller than min. {}, {}".format(class_type, x))
|
||||||
if "max" in info[1] and val > info[1]["max"]:
|
if "max" in info[1] and val > info[1]["max"]:
|
||||||
return (False, "Value bigger than max. {}, {}".format(class_type, x))
|
return (False, "Value bigger than max. {}, {}".format(class_type, x))
|
||||||
|
|
||||||
if isinstance(type_input, list):
|
if isinstance(type_input, list):
|
||||||
if val not in type_input:
|
if val not in type_input:
|
||||||
return (False, "Value not in list. {}, {}: {} not in {}".format(class_type, x, val, type_input))
|
return (False, "Value not in list. {}, {}: {} not in {}".format(class_type, x, val, type_input))
|
||||||
return (True, "")
|
return (True, "")
|
||||||
|
|
||||||
|
result, error = validate(class_inputs['required'])
|
||||||
|
if result:
|
||||||
|
result, error = validate(class_inputs.get('optional', {}), is_optional=True)
|
||||||
|
|
||||||
|
return result, error
|
||||||
|
|
||||||
def validate_prompt(prompt):
|
def validate_prompt(prompt):
|
||||||
outputs = set()
|
outputs = set()
|
||||||
|
|||||||
@ -565,31 +565,35 @@ class ComfyApp {
|
|||||||
const nodeData = defs[nodeId];
|
const nodeData = defs[nodeId];
|
||||||
const node = Object.assign(
|
const node = Object.assign(
|
||||||
function ComfyNode() {
|
function ComfyNode() {
|
||||||
const inputs = nodeData["input"]["required"];
|
function addInputs(self, inputs, config) {
|
||||||
const config = { minWidth: 1, minHeight: 1 };
|
for (const inputName in inputs) {
|
||||||
for (const inputName in inputs) {
|
const inputData = inputs[inputName];
|
||||||
const inputData = inputs[inputName];
|
const type = inputData[0];
|
||||||
const type = inputData[0];
|
|
||||||
|
|
||||||
if (Array.isArray(type)) {
|
if (Array.isArray(type)) {
|
||||||
// Enums e.g. latent rotation
|
// Enums e.g. latent rotation
|
||||||
let defaultValue = type[0];
|
let defaultValue = type[0];
|
||||||
if (inputData[1] && inputData[1].default) {
|
if (inputData[1] && inputData[1].default) {
|
||||||
defaultValue = inputData[1].default;
|
defaultValue = inputData[1].default;
|
||||||
|
}
|
||||||
|
self.addWidget("combo", inputName, defaultValue, () => {}, { values: type });
|
||||||
|
} else if (`${type}:${inputName}` in widgets) {
|
||||||
|
// Support custom widgets by Type:Name
|
||||||
|
Object.assign(config, widgets[`${type}:${inputName}`](self, inputName, inputData, app) || {});
|
||||||
|
} else if (type in widgets) {
|
||||||
|
// Standard type widgets
|
||||||
|
Object.assign(config, widgets[type](self, inputName, inputData, app) || {});
|
||||||
|
} else {
|
||||||
|
// Node connection inputs
|
||||||
|
self.addInput(inputName, type);
|
||||||
}
|
}
|
||||||
this.addWidget("combo", inputName, defaultValue, () => {}, { values: type });
|
|
||||||
} else if (`${type}:${inputName}` in widgets) {
|
|
||||||
// Support custom widgets by Type:Name
|
|
||||||
Object.assign(config, widgets[`${type}:${inputName}`](this, inputName, inputData, app) || {});
|
|
||||||
} else if (type in widgets) {
|
|
||||||
// Standard type widgets
|
|
||||||
Object.assign(config, widgets[type](this, inputName, inputData, app) || {});
|
|
||||||
} else {
|
|
||||||
// Node connection inputs
|
|
||||||
this.addInput(inputName, type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const config = { minWidth: 1, minHeight: 1 };
|
||||||
|
addInputs(this, nodeData["input"]["required"], config);
|
||||||
|
addInputs(this, nodeData["input"]["optional"], config);
|
||||||
|
|
||||||
for (const output of nodeData["output"]) {
|
for (const output of nodeData["output"]) {
|
||||||
this.addOutput(output, output);
|
this.addOutput(output, output);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user