qqwjq1981 commited on
Commit
207e0e7
·
verified ·
1 Parent(s): 54d2997

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
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 {}, pd.DataFrame(), {}
618
 
619
  # Check if there is a condition to evaluate
620
  if "check" in node:
621
- value = execution_results[node["check"]] # Evaluate the check condition
622
- traverse(node.get(value, node.get("default")), previous_output)
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 {}, pd.DataFrame(), {}
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
- output = action_func(**inputs)
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
- return task_analysis, pd.DataFrame(), {}
 
 
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