better place to report extra_info

This commit is contained in:
Chris 2023-10-02 13:25:35 +11:00
parent 7499011289
commit 677e6bb819

View File

@ -411,6 +411,8 @@ def validate_inputs(prompt, item, validated, stack=[]):
validated[unique_id] = ret validated[unique_id] = ret
# don't continue, because we're already here further up the stack # don't continue, because we're already here further up the stack
return ret return ret
# add this node to the stack
stack.append(unique_id) stack.append(unique_id)
for x in required_inputs: for x in required_inputs:
@ -591,6 +593,9 @@ def validate_inputs(prompt, item, validated, stack=[]):
errors.append(error) errors.append(error)
continue continue
# pop the node back off the stack:
stack.pop()
if len(errors) > 0 or valid is not True: if len(errors) > 0 or valid is not True:
ret = (False, errors, unique_id) ret = (False, errors, unique_id)
else: else:
@ -675,25 +680,23 @@ def validate_prompt(prompt):
print(f"* {class_type} {node_id}:") print(f"* {class_type} {node_id}:")
for reason in reasons: for reason in reasons:
print(f" - {reason['message']}: {reason['details']}") print(f" - {reason['message']}: {reason['details']}")
if 'extra_info' in reason:
print(f" - {reason['extra_info']}")
node_errors[node_id]["dependent_outputs"].append(o) node_errors[node_id]["dependent_outputs"].append(o)
print("Output will be ignored") print("Output will be ignored")
if len(good_outputs) == 0: if len(good_outputs) == 0:
errors_list = [] errors_list = []
extra_info = {}
for o, errors in errors: for o, errors in errors:
if errors: for error in errors:
extra_info[o] = [] errors_list.append(f"{error['message']}: {error['details']}")
for error in errors:
errors_list.append(f"{error['message']}: {error['details']}")
extra_info[o].append(error.get('extra_info',""))
errors_list = "\n".join(errors_list) errors_list = "\n".join(errors_list)
error = { error = {
"type": "prompt_outputs_failed_validation", "type": "prompt_outputs_failed_validation",
"message": "Prompt outputs failed validation", "message": "Prompt outputs failed validation",
"details": errors_list, "details": errors_list,
"extra_info": extra_info, "extra_info": {}
} }
return (False, error, list(good_outputs), node_errors) return (False, error, list(good_outputs), node_errors)