in project/paperbench/paperbench/gui/app.py [0:0]
def add_sub_task():
"""Adds a new sub-task to the given parent node."""
with lock: # Use lock to support concurrent requests
data = sanitize_request_data(request.json)
parent_id = data.get("parent_id")
new_requirements = data.get("requirements")
try:
with open(app.config["PATH_TO_PAPER"] / app.config["RUBRIC_FILE_NAME"], "r") as f:
rubric = json.load(f)
root = app.config["NODE_TYPE"].from_dict(rubric)
parent_node = root.find(parent_id)
if args.graded:
new_sub_task = app.config["NODE_TYPE"](
id=random_id(),
task_category=None,
requirements=new_requirements,
weight=1,
score=0.0,
explanation="",
judge_metadata={},
valid_score=True,
sub_tasks=[],
)
else:
new_sub_task = app.config["NODE_TYPE"](
id=random_id(),
task_category=None,
requirements=new_requirements,
weight=1,
sub_tasks=[],
)
if app.config["USE_API"]:
new_task_category = generate_task_category(new_sub_task)
new_sub_task = new_sub_task.set_task_category(new_task_category)
new_parent_node = parent_node.add_sub_task(new_sub_task)
new_root = root.replace(parent_id, new_parent_node)
with open(app.config["PATH_TO_PAPER"] / app.config["RUBRIC_FILE_NAME"], "w") as f:
json.dump(new_root.to_dict(), f, indent=4)
return jsonify({"status": "success"})
except Exception as e:
return jsonify(
{
"status": "error",
"message": f"Error adding sub-task to node {parent_id}: {str(e)}",
}
)