Update agent.py
Browse files
agent.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#
|
2 |
import os
|
3 |
import re
|
4 |
import io
|
@@ -75,9 +75,11 @@ class GaiaAgent:
|
|
75 |
try:
|
76 |
df = pd.read_excel(io.BytesIO(content), engine="openpyxl")
|
77 |
df.columns = [c.lower() for c in df.columns]
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
81 |
except:
|
82 |
return "$0.00"
|
83 |
try:
|
@@ -85,6 +87,28 @@ class GaiaAgent:
|
|
85 |
except:
|
86 |
return ""
|
87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
def format_answer(self, raw, question):
|
89 |
q = question.lower()
|
90 |
raw = raw.strip().strip("\"'")
|
@@ -100,8 +124,7 @@ class GaiaAgent:
|
|
100 |
return ", ".join(items)
|
101 |
|
102 |
if "commutative" in q:
|
103 |
-
|
104 |
-
return ", ".join(items)
|
105 |
|
106 |
if "first name" in q:
|
107 |
return raw.split()[0]
|
@@ -136,9 +159,9 @@ class GaiaAgent:
|
|
136 |
file_bytes, file_type = (None, None)
|
137 |
if task_id:
|
138 |
file_bytes, file_type = self.fetch_file(task_id)
|
|
|
139 |
context = self.handle_file(file_bytes, file_type, question) if file_bytes else self.extract_web_context(question)
|
140 |
|
141 |
-
# fallback: use direct search prompt
|
142 |
if not context.strip():
|
143 |
prompt_map = {
|
144 |
"youtube": "transcript of video site:youtube.com",
|
|
|
1 |
+
# agent_v35.py (logika komutatywna, warunkowe filtrowanie, poprawka chess image)
|
2 |
import os
|
3 |
import re
|
4 |
import io
|
|
|
75 |
try:
|
76 |
df = pd.read_excel(io.BytesIO(content), engine="openpyxl")
|
77 |
df.columns = [c.lower() for c in df.columns]
|
78 |
+
if 'category' in df.columns and 'sales' in df.columns:
|
79 |
+
df['sales'] = pd.to_numeric(df['sales'], errors='coerce')
|
80 |
+
food_df = df[df['category'].str.lower() == 'food']
|
81 |
+
return f"${food_df['sales'].sum():.2f}"
|
82 |
+
return "[MISSING REQUIRED COLUMNS]"
|
83 |
except:
|
84 |
return "$0.00"
|
85 |
try:
|
|
|
87 |
except:
|
88 |
return ""
|
89 |
|
90 |
+
def handle_commutativity(self, question):
|
91 |
+
try:
|
92 |
+
table = {}
|
93 |
+
lines = question.splitlines()
|
94 |
+
header = []
|
95 |
+
for line in lines:
|
96 |
+
if line.strip().startswith("|*"):
|
97 |
+
header = line.strip().split("|")[2:]
|
98 |
+
elif line.strip().startswith("|") and line.count("|") >= 6:
|
99 |
+
parts = line.strip().split("|")[1:-1]
|
100 |
+
key, values = parts[0], parts[1:]
|
101 |
+
table[key] = values
|
102 |
+
S = list(table.keys())
|
103 |
+
non_commutative = set()
|
104 |
+
for i in S:
|
105 |
+
for j in S:
|
106 |
+
if table[i][S.index(j)] != table[j][S.index(i)]:
|
107 |
+
non_commutative.update([i, j])
|
108 |
+
return ", ".join(sorted(non_commutative))
|
109 |
+
except:
|
110 |
+
return ""
|
111 |
+
|
112 |
def format_answer(self, raw, question):
|
113 |
q = question.lower()
|
114 |
raw = raw.strip().strip("\"'")
|
|
|
124 |
return ", ".join(items)
|
125 |
|
126 |
if "commutative" in q:
|
127 |
+
return self.handle_commutativity(question)
|
|
|
128 |
|
129 |
if "first name" in q:
|
130 |
return raw.split()[0]
|
|
|
159 |
file_bytes, file_type = (None, None)
|
160 |
if task_id:
|
161 |
file_bytes, file_type = self.fetch_file(task_id)
|
162 |
+
|
163 |
context = self.handle_file(file_bytes, file_type, question) if file_bytes else self.extract_web_context(question)
|
164 |
|
|
|
165 |
if not context.strip():
|
166 |
prompt_map = {
|
167 |
"youtube": "transcript of video site:youtube.com",
|