mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-30 00:00:26 +08:00
implement optional
This commit is contained in:
parent
dd095efc2c
commit
a3b16a6edc
16
execution.py
16
execution.py
@ -207,12 +207,16 @@ 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):
|
||||||
|
for x in current_inputs:
|
||||||
if x not in inputs:
|
if x not in inputs:
|
||||||
|
if is_optional:
|
||||||
|
return (True, "")
|
||||||
|
else:
|
||||||
return (False, "Required input is missing. {}, {}".format(class_type, x))
|
return (False, "Required input is missing. {}, {}".format(class_type, x))
|
||||||
val = inputs[x]
|
val = inputs[x]
|
||||||
info = required_inputs[x]
|
info = current_inputs[x]
|
||||||
type_input = info[0]
|
type_input = info[0]
|
||||||
if isinstance(val, list):
|
if isinstance(val, list):
|
||||||
if len(val) != 2:
|
if len(val) != 2:
|
||||||
@ -247,6 +251,12 @@ def validate_inputs(prompt, item):
|
|||||||
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()
|
||||||
for x in prompt:
|
for x in prompt:
|
||||||
|
|||||||
@ -565,8 +565,7 @@ 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];
|
||||||
@ -577,18 +576,23 @@ class ComfyApp {
|
|||||||
if (inputData[1] && inputData[1].default) {
|
if (inputData[1] && inputData[1].default) {
|
||||||
defaultValue = inputData[1].default;
|
defaultValue = inputData[1].default;
|
||||||
}
|
}
|
||||||
this.addWidget("combo", inputName, defaultValue, () => {}, { values: type });
|
self.addWidget("combo", inputName, defaultValue, () => {}, { values: type });
|
||||||
} else if (`${type}:${inputName}` in widgets) {
|
} else if (`${type}:${inputName}` in widgets) {
|
||||||
// Support custom widgets by Type:Name
|
// Support custom widgets by Type:Name
|
||||||
Object.assign(config, widgets[`${type}:${inputName}`](this, inputName, inputData, app) || {});
|
Object.assign(config, widgets[`${type}:${inputName}`](self, inputName, inputData, app) || {});
|
||||||
} else if (type in widgets) {
|
} else if (type in widgets) {
|
||||||
// Standard type widgets
|
// Standard type widgets
|
||||||
Object.assign(config, widgets[type](this, inputName, inputData, app) || {});
|
Object.assign(config, widgets[type](self, inputName, inputData, app) || {});
|
||||||
} else {
|
} else {
|
||||||
// Node connection inputs
|
// Node connection inputs
|
||||||
this.addInput(inputName, type);
|
self.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