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

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +25 -2
agent.py CHANGED
@@ -87,6 +87,27 @@ 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
  # Dynamic parser for operation table
91
  import re
92
  import pandas as pd
@@ -106,9 +127,11 @@ def answer_question(question: str, task_id: str = None) -> str:
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
 
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
+ 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]
96
+ data_rows = [re.split(r'\|+', row)[1:-1] for row in table_lines[1:]]
97
+ index = [row[0] for row in data_rows]
98
+ matrix = [row[1:] for row in data_rows]
99
+ df = pd.DataFrame(matrix, index=index, columns=headers)
100
+
101
+ non_comm = set()
102
+ for a in df.index:
103
+ for b in df.columns:
104
+ if df.at[a, b] != df.at[b, a]:
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
  non_comm.add(a)
128
  non_comm.add(b)
129
  result = ", ".join(sorted(non_comm))
130
+ file_context += f"
131
+ [Parsed Non-Commutative Set] {result}"
132
  except Exception as e:
133
+ file_context += f"
134
+ [Table Parse Error] {e}"
135
  # Parse table to extract non-commutative elements
136
  import re
137
  import pandas as pd