Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -600,7 +600,6 @@ def fn_analyze_task(project_context, task_description):
|
|
600 |
|
601 |
# In[13]:
|
602 |
|
603 |
-
|
604 |
# Recursive Task Executor
|
605 |
def fn_process_task(project_desc_table, task_description, bucket_name='curify'):
|
606 |
|
@@ -614,13 +613,19 @@ def fn_process_task(project_desc_table, task_description, bucket_name='curify'):
|
|
614 |
|
615 |
def traverse(node, previous_output=None):
|
616 |
if not node: # If the node is None or invalid
|
617 |
-
return
|
618 |
|
619 |
# Check if there is a condition to evaluate
|
620 |
if "check" in node:
|
621 |
-
|
622 |
-
|
623 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
624 |
# If the node contains an action
|
625 |
elif "action" in node:
|
626 |
action_name = node["action"]
|
@@ -629,15 +634,21 @@ def fn_process_task(project_desc_table, task_description, bucket_name='curify'):
|
|
629 |
if input_key in execution_results.keys():
|
630 |
inputs = {input_key: execution_results[input_key]}
|
631 |
else:
|
|
|
632 |
logger.error(f"Workflow action {action_name} input key {input_key} not in execution_results.")
|
633 |
-
return
|
634 |
|
635 |
logger.debug(f"Executing: {action_name} with inputs: {inputs}")
|
636 |
|
637 |
# Execute the action function
|
638 |
action_func = action_map.get(action_name, unsupported_task)
|
639 |
-
|
640 |
-
|
|
|
|
|
|
|
|
|
|
|
641 |
# Store execution results or append to previous outputs
|
642 |
execution_status.append({"action": action_name, "output": output})
|
643 |
|
@@ -656,15 +667,15 @@ def fn_process_task(project_desc_table, task_description, bucket_name='curify'):
|
|
656 |
try:
|
657 |
traverse(TASK_WORKFLOW_TREE["start"])
|
658 |
execution_results['doc_url'] = generate_document(task_description, execution_results)
|
659 |
-
return task_analysis, pd.DataFrame(execution_status), execution_results
|
660 |
except Exception as e:
|
661 |
logger.error(f"Traverse Error: {e}")
|
662 |
-
|
|
|
|
|
663 |
else:
|
664 |
logger.error("Empty task analysis.")
|
665 |
return {}, pd.DataFrame(), {}
|
666 |
|
667 |
-
|
668 |
# In[14]:
|
669 |
|
670 |
|
|
|
600 |
|
601 |
# In[13]:
|
602 |
|
|
|
603 |
# Recursive Task Executor
|
604 |
def fn_process_task(project_desc_table, task_description, bucket_name='curify'):
|
605 |
|
|
|
613 |
|
614 |
def traverse(node, previous_output=None):
|
615 |
if not node: # If the node is None or invalid
|
616 |
+
return # Exit if the node is invalid
|
617 |
|
618 |
# Check if there is a condition to evaluate
|
619 |
if "check" in node:
|
620 |
+
# Safely attempt to retrieve the value from execution_results
|
621 |
+
if node["check"] in execution_results:
|
622 |
+
value = execution_results[node["check"]] # Evaluate the check condition
|
623 |
+
traverse(node.get(value, node.get("default")), previous_output)
|
624 |
+
else:
|
625 |
+
# Log an error and exit, but keep partial results
|
626 |
+
logger.error(f"Key '{node['check']}' not found in execution_results.")
|
627 |
+
return
|
628 |
+
|
629 |
# If the node contains an action
|
630 |
elif "action" in node:
|
631 |
action_name = node["action"]
|
|
|
634 |
if input_key in execution_results.keys():
|
635 |
inputs = {input_key: execution_results[input_key]}
|
636 |
else:
|
637 |
+
# Log an error and exit, but keep partial results
|
638 |
logger.error(f"Workflow action {action_name} input key {input_key} not in execution_results.")
|
639 |
+
return
|
640 |
|
641 |
logger.debug(f"Executing: {action_name} with inputs: {inputs}")
|
642 |
|
643 |
# Execute the action function
|
644 |
action_func = action_map.get(action_name, unsupported_task)
|
645 |
+
try:
|
646 |
+
output = action_func(**inputs)
|
647 |
+
except Exception as e:
|
648 |
+
# Handle action function failure
|
649 |
+
logger.error(f"Error executing action '{action_name}': {e}")
|
650 |
+
return
|
651 |
+
|
652 |
# Store execution results or append to previous outputs
|
653 |
execution_status.append({"action": action_name, "output": output})
|
654 |
|
|
|
667 |
try:
|
668 |
traverse(TASK_WORKFLOW_TREE["start"])
|
669 |
execution_results['doc_url'] = generate_document(task_description, execution_results)
|
|
|
670 |
except Exception as e:
|
671 |
logger.error(f"Traverse Error: {e}")
|
672 |
+
finally:
|
673 |
+
# Always return partial results, even if an error occurs
|
674 |
+
return task_analysis, pd.DataFrame(execution_status), execution_results
|
675 |
else:
|
676 |
logger.error("Empty task analysis.")
|
677 |
return {}, pd.DataFrame(), {}
|
678 |
|
|
|
679 |
# In[14]:
|
680 |
|
681 |
|