dawid-lorek commited on
Commit
81cdaff
·
verified ·
1 Parent(s): 6ad00cc

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +23 -1
agent.py CHANGED
@@ -87,7 +87,29 @@ def answer_question(question: str, task_id: str = None) -> str:
87
  yt = get_youtube_transcript(question)
88
  file_context += f"\n[YouTube Transcript] {yt}"
89
  elif "* on the set" in question and file_context:
90
- # Parse table to extract non-commutative elements
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  import re
92
  import pandas as pd
93
 
 
87
  yt = get_youtube_transcript(question)
88
  file_context += f"\n[YouTube Transcript] {yt}"
89
  elif "* on the set" in question and file_context:
90
+ # Dynamic parser for operation table
91
+ import re
92
+ import pandas as pd
93
+
94
+ try:
95
+ table_lines = [line.strip() for line in file_context.splitlines() if '|' in line and '*' not in line[:2]]
96
+ headers = re.split(r'\|+', table_lines[0])[1:-1]
97
+ data_rows = [re.split(r'\|+', row)[1:-1] for row in table_lines[1:]]
98
+ index = [row[0] for row in data_rows]
99
+ matrix = [row[1:] for row in data_rows]
100
+ df = pd.DataFrame(matrix, index=index, columns=headers)
101
+
102
+ non_comm = set()
103
+ for a in df.index:
104
+ for b in df.columns:
105
+ if df.at[a, b] != df.at[b, a]:
106
+ non_comm.add(a)
107
+ non_comm.add(b)
108
+ result = ", ".join(sorted(non_comm))
109
+ file_context += f"\n[Parsed Non-Commutative Set] {result}"
110
+ except Exception as e:
111
+ file_context += f"\n[Table Parse Error] {e}"
112
+ # Parse table to extract non-commutative elements
113
  import re
114
  import pandas as pd
115