Merge branch 'comfyanonymous:master' into feature/preview-latent

This commit is contained in:
Dr.Lt.Data 2023-05-23 09:14:37 +09:00 committed by GitHub
commit 9cedbbbcfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 18 deletions

View File

@ -299,18 +299,18 @@ def validate_inputs(prompt, item, validated):
required_inputs = class_inputs['required'] required_inputs = class_inputs['required']
for x in required_inputs: for x in required_inputs:
if x not in inputs: if x not in inputs:
return (False, "Required input is missing. {}, {}".format(class_type, x)) return (False, "Required input is missing. {}, {}".format(class_type, x), unique_id)
val = inputs[x] val = inputs[x]
info = required_inputs[x] info = required_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:
return (False, "Bad Input. {}, {}".format(class_type, x)) return (False, "Bad Input. {}, {}".format(class_type, x), unique_id)
o_id = val[0] o_id = val[0]
o_class_type = prompt[o_id]['class_type'] o_class_type = prompt[o_id]['class_type']
r = nodes.NODE_CLASS_MAPPINGS[o_class_type].RETURN_TYPES r = nodes.NODE_CLASS_MAPPINGS[o_class_type].RETURN_TYPES
if r[val[1]] != type_input: if r[val[1]] != type_input:
return (False, "Return type mismatch. {}, {}, {} != {}".format(class_type, x, r[val[1]], type_input)) return (False, "Return type mismatch. {}, {}, {} != {}".format(class_type, x, r[val[1]], type_input), unique_id)
r = validate_inputs(prompt, o_id, validated) r = validate_inputs(prompt, o_id, validated)
if r[0] == False: if r[0] == False:
validated[o_id] = r validated[o_id] = r
@ -328,9 +328,9 @@ def validate_inputs(prompt, item, validated):
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 of {}. {}, {}".format(val, info[1]["min"], class_type, x)) return (False, "Value {} smaller than min of {}. {}, {}".format(val, info[1]["min"], class_type, x), unique_id)
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 of {}. {}, {}".format(val, info[1]["max"], class_type, x)) return (False, "Value {} bigger than max of {}. {}, {}".format(val, info[1]["max"], class_type, x), unique_id)
if hasattr(obj_class, "VALIDATE_INPUTS"): if hasattr(obj_class, "VALIDATE_INPUTS"):
input_data_all = get_input_data(inputs, obj_class, unique_id) input_data_all = get_input_data(inputs, obj_class, unique_id)
@ -338,13 +338,13 @@ def validate_inputs(prompt, item, validated):
ret = map_node_over_list(obj_class, input_data_all, "VALIDATE_INPUTS") ret = map_node_over_list(obj_class, input_data_all, "VALIDATE_INPUTS")
for r in ret: for r in ret:
if r != True: if r != True:
return (False, "{}, {}".format(class_type, r)) return (False, "{}, {}".format(class_type, r), unique_id)
else: else:
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), unique_id)
ret = (True, "") ret = (True, "", unique_id)
validated[unique_id] = ret validated[unique_id] = ret
return ret return ret
@ -356,10 +356,11 @@ def validate_prompt(prompt):
outputs.add(x) outputs.add(x)
if len(outputs) == 0: if len(outputs) == 0:
return (False, "Prompt has no outputs") return (False, "Prompt has no outputs", [], [])
good_outputs = set() good_outputs = set()
errors = [] errors = []
node_errors = {}
validated = {} validated = {}
for o in outputs: for o in outputs:
valid = False valid = False
@ -368,6 +369,7 @@ def validate_prompt(prompt):
m = validate_inputs(prompt, o, validated) m = validate_inputs(prompt, o, validated)
valid = m[0] valid = m[0]
reason = m[1] reason = m[1]
node_id = m[2]
except Exception as e: except Exception as e:
print(traceback.format_exc()) print(traceback.format_exc())
valid = False valid = False
@ -379,12 +381,15 @@ def validate_prompt(prompt):
print("Failed to validate prompt for output {} {}".format(o, reason)) print("Failed to validate prompt for output {} {}".format(o, reason))
print("output will be ignored") print("output will be ignored")
errors += [(o, reason)] errors += [(o, reason)]
if node_id not in node_errors:
node_errors[node_id] = {"message": reason, "dependent_outputs": []}
node_errors[node_id]["dependent_outputs"].append(o)
if len(good_outputs) == 0: if len(good_outputs) == 0:
errors_list = "\n".join(set(map(lambda a: "{}".format(a[1]), errors))) errors_list = "\n".join(set(map(lambda a: "{}".format(a[1]), errors)))
return (False, "Prompt has no properly connected outputs\n {}".format(errors_list)) return (False, "Prompt has no properly connected outputs\n {}".format(errors_list), list(good_outputs), node_errors)
return (True, "", list(good_outputs)) return (True, "", list(good_outputs), node_errors)
class PromptQueue: class PromptQueue:

View File

@ -272,6 +272,11 @@ class PromptServer():
info['display_name'] = nodes.NODE_DISPLAY_NAME_MAPPINGS[node_class] if node_class in nodes.NODE_DISPLAY_NAME_MAPPINGS.keys() else node_class info['display_name'] = nodes.NODE_DISPLAY_NAME_MAPPINGS[node_class] if node_class in nodes.NODE_DISPLAY_NAME_MAPPINGS.keys() else node_class
info['description'] = '' info['description'] = ''
info['category'] = 'sd' info['category'] = 'sd'
if hasattr(obj_class, 'OUTPUT_NODE') and obj_class.OUTPUT_NODE == True:
info['output_node'] = True
else:
info['output_node'] = False
if hasattr(obj_class, 'CATEGORY'): if hasattr(obj_class, 'CATEGORY'):
info['category'] = obj_class.CATEGORY info['category'] = obj_class.CATEGORY
return info return info
@ -336,9 +341,9 @@ class PromptServer():
return web.json_response({"prompt_id": prompt_id}) return web.json_response({"prompt_id": prompt_id})
else: else:
print("invalid prompt:", valid[1]) print("invalid prompt:", valid[1])
return web.json_response({"error": valid[1]}, status=400) return web.json_response({"error": valid[1], "node_errors": valid[3]}, status=400)
else: else:
return web.json_response({"error": "no prompt"}, status=400) return web.json_response({"error": "no prompt", "node_errors": []}, status=400)
@routes.post("/queue") @routes.post("/queue")
async def post_queue(request): async def post_queue(request):

View File

@ -174,7 +174,7 @@ const els = {}
// const ctxMenu = LiteGraph.ContextMenu; // const ctxMenu = LiteGraph.ContextMenu;
app.registerExtension({ app.registerExtension({
name: id, name: id,
init() { addCustomNodeDefs(node_defs) {
const sortObjectKeys = (unordered) => { const sortObjectKeys = (unordered) => {
return Object.keys(unordered).sort().reduce((obj, key) => { return Object.keys(unordered).sort().reduce((obj, key) => {
obj[key] = unordered[key]; obj[key] = unordered[key];
@ -182,10 +182,10 @@ app.registerExtension({
}, {}); }, {});
}; };
const getSlotTypes = async () => { function getSlotTypes() {
var types = []; var types = [];
const defs = await api.getNodeDefs(); const defs = node_defs;
for (const nodeId in defs) { for (const nodeId in defs) {
const nodeData = defs[nodeId]; const nodeData = defs[nodeId];
@ -212,8 +212,8 @@ app.registerExtension({
return types; return types;
}; };
const completeColorPalette = async (colorPalette) => { function completeColorPalette(colorPalette) {
var types = await getSlotTypes(); var types = getSlotTypes();
for (const type of types) { for (const type of types) {
if (!colorPalette.colors.node_slot[type]) { if (!colorPalette.colors.node_slot[type]) {