dawid-lorek commited on
Commit
7c0f5ac
·
verified ·
1 Parent(s): 5d406c0

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +10 -3
agent.py CHANGED
@@ -1,4 +1,4 @@
1
- # Agent V45poprawiony string literal (prompt)
2
  import os
3
  import re
4
  import io
@@ -65,7 +65,8 @@ class GaiaAgent:
65
  if "excel" in ctype:
66
  df = pd.read_excel(io.BytesIO(content), engine="openpyxl")
67
  df.columns = [c.lower().strip() for c in df.columns]
68
- df = df.dropna(subset=['category', 'sales'], errors='ignore')
 
69
  df['sales'] = pd.to_numeric(df['sales'], errors='coerce')
70
  if 'category' in df.columns:
71
  df = df[df['category'].str.lower() == 'food']
@@ -83,11 +84,17 @@ class GaiaAgent:
83
  except:
84
  return text[:100]
85
 
 
 
 
 
86
  def format_answer(self, answer, question):
87
  q = question.lower()
88
  raw = answer.strip().strip("\"'")
89
  if "ingredient" in q:
90
  return self.extract_ingredients(raw)
 
 
91
  if "algebraic notation" in q:
92
  m = re.search(r"[KQBNR]?[a-h]?[1-8]?x?[a-h][1-8][+#]?", raw)
93
  return m.group(0) if m else raw
@@ -122,7 +129,7 @@ Question:
122
  {question}
123
  Answer:"""
124
  answer = self.ask(prompt)
125
- if not answer or "[ERROR" in answer:
126
  fallback = self.search_context(question)
127
  retry_prompt = f"""Use this context to answer:
128
  {fallback}
 
1
+ # Agent V46V26 + web fallback, stricte parsing, Excel fix
2
  import os
3
  import re
4
  import io
 
65
  if "excel" in ctype:
66
  df = pd.read_excel(io.BytesIO(content), engine="openpyxl")
67
  df.columns = [c.lower().strip() for c in df.columns]
68
+ if 'sales' not in df.columns:
69
+ return "$0.00"
70
  df['sales'] = pd.to_numeric(df['sales'], errors='coerce')
71
  if 'category' in df.columns:
72
  df = df[df['category'].str.lower() == 'food']
 
84
  except:
85
  return text[:100]
86
 
87
+ def sanitize_commutative_set(self, raw):
88
+ s = re.findall(r"\b[a-e]\b", raw)
89
+ return ", ".join(sorted(set(s))) if s else raw
90
+
91
  def format_answer(self, answer, question):
92
  q = question.lower()
93
  raw = answer.strip().strip("\"'")
94
  if "ingredient" in q:
95
  return self.extract_ingredients(raw)
96
+ if "commutative" in q:
97
+ return self.sanitize_commutative_set(raw)
98
  if "algebraic notation" in q:
99
  m = re.search(r"[KQBNR]?[a-h]?[1-8]?x?[a-h][1-8][+#]?", raw)
100
  return m.group(0) if m else raw
 
129
  {question}
130
  Answer:"""
131
  answer = self.ask(prompt)
132
+ if not answer or "[ERROR" in answer or "step execution failed" in answer:
133
  fallback = self.search_context(question)
134
  retry_prompt = f"""Use this context to answer:
135
  {fallback}