dawid-lorek commited on
Commit
aef7057
·
verified ·
1 Parent(s): 28d119a

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +13 -11
agent.py CHANGED
@@ -1,4 +1,4 @@
1
- # agent_v29.py
2
  import os
3
  import re
4
  import io
@@ -28,7 +28,7 @@ class GaiaAgent:
28
  response = self.client.chat.completions.create(
29
  model=model,
30
  messages=[
31
- {"role": "system", "content": "You are a precise assistant. Return only a short factual answer. Format appropriately. Never guess."},
32
  {"role": "user", "content": prompt.strip() + "\nAnswer:"}
33
  ],
34
  temperature=0.0,
@@ -51,7 +51,7 @@ class GaiaAgent:
51
  def ask_image(self, image_bytes, question):
52
  image_b64 = base64.b64encode(image_bytes).decode("utf-8")
53
  messages = [
54
- {"role": "system", "content": "Answer with only the correct chess move in algebraic notation."},
55
  {
56
  "role": "user",
57
  "content": [
@@ -68,9 +68,10 @@ class GaiaAgent:
68
  df = pd.read_excel(io.BytesIO(file_bytes), engine="openpyxl")
69
  df.columns = [col.lower() for col in df.columns]
70
  if 'category' in df.columns and 'sales' in df.columns:
71
- food_df = df[df['category'].str.contains('food', case=False)]
 
72
  total = food_df['sales'].sum()
73
- return f"${total:.2f}"
74
  except Exception:
75
  pass
76
  return "$0.00"
@@ -78,6 +79,7 @@ class GaiaAgent:
78
  def extract_answer(self, raw, question):
79
  q = question.lower()
80
  raw = raw.strip().strip("\"'").strip()
 
81
 
82
  if "studio albums" in q:
83
  try:
@@ -91,8 +93,9 @@ class GaiaAgent:
91
  return match.group(1) if match else raw
92
 
93
  if "vegetables" in q or "ingredients" in q:
94
- list_raw = re.findall(r"[a-zA-Z]+(?: [a-zA-Z]+)?", raw)
95
- return ", ".join(sorted(set(i.lower() for i in list_raw)))
 
96
 
97
  if "usd with two decimal places" in q:
98
  match = re.search(r"\$?([0-9]+(?:\.[0-9]{1,2})?)", raw)
@@ -132,12 +135,11 @@ class GaiaAgent:
132
  return self.ask(f"Video summary: {summary}\n\n{question}")
133
 
134
  if "malko competition" in question.lower():
135
- search = self.get_web_info("list of Malko Competition winners after 1977 and their nationalities")
136
  return self.ask(f"Web result: {search}\n\n{question}")
137
 
138
  if "commutative" in question:
139
- table_text = question.strip()
140
- return self.ask(f"Analyze the following table for non-commutative pairs:\n{table_text}\nList only the elements involved in alphabetical order, comma separated.")
141
 
142
  if file_bytes and "image" in ctype:
143
  raw = self.ask_image(file_bytes, question)
@@ -156,4 +158,4 @@ class GaiaAgent:
156
  except Exception as e:
157
  return f"[ERROR: {e}]"
158
 
159
- return self.extract_answer(raw, question)
 
1
+ # agent_v30.py
2
  import os
3
  import re
4
  import io
 
28
  response = self.client.chat.completions.create(
29
  model=model,
30
  messages=[
31
+ {"role": "system", "content": "Return only a short factual answer. Format it properly. Never guess."},
32
  {"role": "user", "content": prompt.strip() + "\nAnswer:"}
33
  ],
34
  temperature=0.0,
 
51
  def ask_image(self, image_bytes, question):
52
  image_b64 = base64.b64encode(image_bytes).decode("utf-8")
53
  messages = [
54
+ {"role": "system", "content": "Return only the winning move in chess algebraic notation (e.g., Qd1). No explanation."},
55
  {
56
  "role": "user",
57
  "content": [
 
68
  df = pd.read_excel(io.BytesIO(file_bytes), engine="openpyxl")
69
  df.columns = [col.lower() for col in df.columns]
70
  if 'category' in df.columns and 'sales' in df.columns:
71
+ df['sales'] = pd.to_numeric(df['sales'], errors='coerce')
72
+ food_df = df[df['category'].str.lower().str.contains('food')]
73
  total = food_df['sales'].sum()
74
+ return f"${total:.2f}" if not pd.isna(total) else "$0.00"
75
  except Exception:
76
  pass
77
  return "$0.00"
 
79
  def extract_answer(self, raw, question):
80
  q = question.lower()
81
  raw = raw.strip().strip("\"'").strip()
82
+ raw = re.sub(r"^[-•\s]*", "", raw)
83
 
84
  if "studio albums" in q:
85
  try:
 
93
  return match.group(1) if match else raw
94
 
95
  if "vegetables" in q or "ingredients" in q:
96
+ unwanted = {"pure", "extract", "granulated", "sugar", "juice", "vanilla", "ripe", "fresh", "whole", "bean", "pinch", "cups", "salt", "water"}
97
+ terms = [t.lower() for t in re.findall(r"[a-zA-Z]+(?: [a-zA-Z]+)?", raw)]
98
+ return ", ".join(sorted(set(t for t in terms if t.split()[0] not in unwanted)))
99
 
100
  if "usd with two decimal places" in q:
101
  match = re.search(r"\$?([0-9]+(?:\.[0-9]{1,2})?)", raw)
 
135
  return self.ask(f"Video summary: {summary}\n\n{question}")
136
 
137
  if "malko competition" in question.lower():
138
+ search = self.get_web_info("malko competition winners after 1977 yugoslavia site:wikipedia.org")
139
  return self.ask(f"Web result: {search}\n\n{question}")
140
 
141
  if "commutative" in question:
142
+ return self.ask(f"Based on this table, which elements show the operation is not commutative?\n{question}\nList them comma-separated, alphabetically.")
 
143
 
144
  if file_bytes and "image" in ctype:
145
  raw = self.ask_image(file_bytes, question)
 
158
  except Exception as e:
159
  return f"[ERROR: {e}]"
160
 
161
+ return self.extract_answer(raw, question)