dawid-lorek commited on
Commit
9daa24b
·
verified ·
1 Parent(s): 7ab9d5a

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +12 -34
agent.py CHANGED
@@ -27,8 +27,8 @@ class GaiaAgent:
27
  response = self.client.chat.completions.create(
28
  model=model,
29
  messages=[
30
- {"role": "system", "content": "You are a precise assistant. Only return the final answer. Do not guess. Use reasoning and tools when needed."},
31
- {"role": "user", "content": prompt.strip() + "\nFinal Answer:"}
32
  ],
33
  temperature=0.0,
34
  )
@@ -60,32 +60,13 @@ class GaiaAgent:
60
  try:
61
  df = pd.read_excel(io.BytesIO(file_bytes), engine="openpyxl")
62
  if 'category' in df.columns and 'sales' in df.columns:
63
- food_df = df[df['category'].str.lower() == 'food']
64
  total = food_df['sales'].sum()
65
  return f"${total:.2f}"
66
  return "$0.00"
67
  except Exception:
68
  return "$0.00"
69
 
70
- def analyze_commutativity(self, question):
71
- try:
72
- rows = re.findall(r"\|([a-e])\|([a-e\|]+)\|", question)
73
- table = {}
74
- for row in rows:
75
- key, values = row
76
- table[key] = values.strip('|').split('|')
77
- elements = list(table.keys())
78
- non_comm = set()
79
- for i, x in enumerate(elements):
80
- for j, y in enumerate(elements):
81
- a = table[x][j]
82
- b = table[y][i]
83
- if a != b:
84
- non_comm.update([x, y])
85
- return ", ".join(sorted(non_comm))
86
- except:
87
- return ""
88
-
89
  def search_web(self, query: str) -> str:
90
  try:
91
  return self.search_tool.run(query)
@@ -107,10 +88,6 @@ class GaiaAgent:
107
  match = re.search(r"\b([KQBNR]?[a-h]?[1-8]?x?[a-h][1-8][+#]?)\b", text)
108
  return match.group(1) if match else text
109
 
110
- if "comma separated list" in q:
111
- words = re.findall(r"[a-zA-Z][a-zA-Z ]+[a-zA-Z]", text)
112
- return ", ".join(sorted(set(w.strip().lower() for w in words)))
113
-
114
  if "usd with two decimal places" in q:
115
  match = re.search(r"\$?([0-9]+(?:\.[0-9]{1,2})?)", text)
116
  return f"${float(match.group(1)):.2f}" if match else "$0.00"
@@ -148,14 +125,15 @@ class GaiaAgent:
148
  file_bytes, ctype = self.fetch_file(task_id)
149
 
150
  try:
151
- if "malko" in question.lower() and "no longer exists" in question.lower():
152
- webinfo = self.search_web("malko competition winners 20th century country that no longer exists")
153
- return self.ask(f"Use the following info to answer the question.\nWeb Search Result:\n{webinfo}\n\nQuestion: {question}")
 
 
154
 
155
- if "commutative" in question.lower():
156
- result = self.analyze_commutativity(question)
157
- if result:
158
- return result
159
 
160
  if file_bytes and "image" in ctype:
161
  raw = self.ask_image(file_bytes, question)
@@ -174,4 +152,4 @@ class GaiaAgent:
174
  except Exception as e:
175
  return f"[ERROR: {e}]"
176
 
177
- return self.extract_answer(raw, question)
 
27
  response = self.client.chat.completions.create(
28
  model=model,
29
  messages=[
30
+ {"role": "system", "content": "You are a precise assistant. Answer concisely and factually. Do not guess."},
31
+ {"role": "user", "content": prompt.strip() + "\nAnswer:"}
32
  ],
33
  temperature=0.0,
34
  )
 
60
  try:
61
  df = pd.read_excel(io.BytesIO(file_bytes), engine="openpyxl")
62
  if 'category' in df.columns and 'sales' in df.columns:
63
+ food_df = df[df['category'].str.lower().str.contains("food")]
64
  total = food_df['sales'].sum()
65
  return f"${total:.2f}"
66
  return "$0.00"
67
  except Exception:
68
  return "$0.00"
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def search_web(self, query: str) -> str:
71
  try:
72
  return self.search_tool.run(query)
 
88
  match = re.search(r"\b([KQBNR]?[a-h]?[1-8]?x?[a-h][1-8][+#]?)\b", text)
89
  return match.group(1) if match else text
90
 
 
 
 
 
91
  if "usd with two decimal places" in q:
92
  match = re.search(r"\$?([0-9]+(?:\.[0-9]{1,2})?)", text)
93
  return f"${float(match.group(1)):.2f}" if match else "$0.00"
 
125
  file_bytes, ctype = self.fetch_file(task_id)
126
 
127
  try:
128
+ if "youtube.com" in question.lower():
129
+ video_id_match = re.search(r"v=([\w-]+)", question)
130
+ if video_id_match:
131
+ search = self.search_web(f"summary or transcript of YouTube video {video_id_match.group(1)}")
132
+ return self.ask(f"Based on this video content:\n{search}\n\n{question}")
133
 
134
+ if "malko competition" in question.lower() and "no longer exists" in question.lower():
135
+ webinfo = self.search_web("malko competition winners 20th century nationality country that no longer exists")
136
+ return self.ask(f"Based on this info:\n{webinfo}\n\n{question}")
 
137
 
138
  if file_bytes and "image" in ctype:
139
  raw = self.ask_image(file_bytes, question)
 
152
  except Exception as e:
153
  return f"[ERROR: {e}]"
154
 
155
+ return self.extract_answer(raw, question)