dawid-lorek commited on
Commit
8c50e71
·
verified ·
1 Parent(s): 30a91c5

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +31 -6
agent.py CHANGED
@@ -90,6 +90,25 @@ def answer_question(question: str, task_id: str = None) -> str:
90
  try:
91
  import re
92
  import pandas as pd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  table_lines = [line.strip() for line in file_context.splitlines() if '|' in line and '*' not in line[:2]]
95
  headers = re.split(r'\|+', table_lines[0])[1:-1]
@@ -105,9 +124,11 @@ def answer_question(question: str, task_id: str = None) -> str:
105
  non_comm.add(a)
106
  non_comm.add(b)
107
  result = ", ".join(sorted(non_comm))
108
- file_context += f"\n[Parsed Non-Commutative Set] {result}"
 
109
  except Exception as e:
110
- file_context += f"\n[Table Parse Error] {e}"
 
111
  # Dynamic parser for operation table
112
  import re
113
  import pandas as pd
@@ -127,9 +148,11 @@ def answer_question(question: str, task_id: str = None) -> str:
127
  non_comm.add(a)
128
  non_comm.add(b)
129
  result = ", ".join(sorted(non_comm))
130
- file_context += f"[Parsed Non-Commutative Set] {result}"
 
131
  except Exception as e:
132
- file_context += f"[Table Parse Error] {e}"
 
133
  # Parse table to extract non-commutative elements
134
  import re
135
  import pandas as pd
@@ -149,6 +172,8 @@ def answer_question(question: str, task_id: str = None) -> str:
149
  non_comm.add(a)
150
  non_comm.add(b)
151
  result = ", ".join(sorted(non_comm))
152
- file_context += f"[Parsed Non-Commutative Set] {result}"
 
153
  except Exception as e:
154
- file_context += f"[Table Parse Error] {e}"
 
 
90
  try:
91
  import re
92
  import pandas as pd
93
+ table_lines = [line.strip() for line in file_context.splitlines() if '|' in line and '*' not in line[:2]]
94
+ headers = re.split(r'\|+', table_lines[0])[1:-1]
95
+ data_rows = [re.split(r'\|+', row)[1:-1] for row in table_lines[1:]]
96
+ index = [row[0] for row in data_rows]
97
+ matrix = [row[1:] for row in data_rows]
98
+ df = pd.DataFrame(matrix, index=index, columns=headers)
99
+ non_comm = set()
100
+ for a in df.index:
101
+ for b in df.columns:
102
+ if df.at[a, b] != df.at[b, a]:
103
+ non_comm.add(a)
104
+ non_comm.add(b)
105
+ result = ", ".join(sorted(non_comm))
106
+ file_context += f" [Parsed Non-Commutative Set] {result}"
107
+ except Exception as e:
108
+ file_context += f" [Table Parse Error] {e}"
109
+ try:
110
+ import re
111
+ import pandas as pd
112
 
113
  table_lines = [line.strip() for line in file_context.splitlines() if '|' in line and '*' not in line[:2]]
114
  headers = re.split(r'\|+', table_lines[0])[1:-1]
 
124
  non_comm.add(a)
125
  non_comm.add(b)
126
  result = ", ".join(sorted(non_comm))
127
+ file_context += f"
128
+ [Parsed Non-Commutative Set] {result}"
129
  except Exception as e:
130
+ file_context += f"
131
+ [Table Parse Error] {e}"
132
  # Dynamic parser for operation table
133
  import re
134
  import pandas as pd
 
148
  non_comm.add(a)
149
  non_comm.add(b)
150
  result = ", ".join(sorted(non_comm))
151
+ file_context += f"
152
+ [Parsed Non-Commutative Set] {result}"
153
  except Exception as e:
154
+ file_context += f"
155
+ [Table Parse Error] {e}"
156
  # Parse table to extract non-commutative elements
157
  import re
158
  import pandas as pd
 
172
  non_comm.add(a)
173
  non_comm.add(b)
174
  result = ", ".join(sorted(non_comm))
175
+ file_context += f"
176
+ [Parsed Non-Commutative Set] {result}"
177
  except Exception as e:
178
+ file_context += f"
179
+ [Table Parse Error] {e}"