huytofu92 commited on
Commit
7d82e4f
·
1 Parent(s): 3db6b5f

properly assemble dataframe

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -54,6 +54,8 @@ class BasicAgent:
54
 
55
  # Log steps
56
  all_steps = self.agent.master_agent.memory.steps
 
 
57
  for step in all_steps:
58
  if isinstance(step, ActionStep):
59
  step_class = "ActionStep"
@@ -69,11 +71,19 @@ class BasicAgent:
69
  step_class = "UnknownStep"
70
 
71
  step_dict = step.dict()
72
- df_agent_steps.iloc[len(df_agent_steps)] = "None"
73
- df_agent_steps.iloc[len(df_agent_steps), df_agent_steps.columns.get_loc('task_id')] = task_id
74
- df_agent_steps.iloc[len(df_agent_steps), df_agent_steps.columns.get_loc('step_class')] = step_class
 
 
75
  for key, value in step_dict.items():
76
- df_agent_steps.iloc[len(df_agent_steps), df_agent_steps.columns.get_loc(key)] = value
 
 
 
 
 
 
77
 
78
  print(f"Agent returning fixed answer: {fixed_answer}")
79
  return fixed_answer, df_agent_steps
 
54
 
55
  # Log steps
56
  all_steps = self.agent.master_agent.memory.steps
57
+ new_rows = [] # List to store new rows
58
+
59
  for step in all_steps:
60
  if isinstance(step, ActionStep):
61
  step_class = "ActionStep"
 
71
  step_class = "UnknownStep"
72
 
73
  step_dict = step.dict()
74
+ # Create a new row with default None values
75
+ new_row = {col: None for col in df_agent_steps.columns}
76
+ # Update with actual values
77
+ new_row['task_id'] = task_id
78
+ new_row['step_class'] = step_class
79
  for key, value in step_dict.items():
80
+ if key in df_agent_steps.columns:
81
+ new_row[key] = value
82
+ new_rows.append(new_row)
83
+
84
+ # Append all new rows at once
85
+ if new_rows:
86
+ df_agent_steps = pd.concat([df_agent_steps, pd.DataFrame(new_rows)], ignore_index=True)
87
 
88
  print(f"Agent returning fixed answer: {fixed_answer}")
89
  return fixed_answer, df_agent_steps