ana-35 commited on
Commit
02a45be
·
1 Parent(s): f8a38a7

improving prompts and file reader

Browse files
Files changed (2) hide show
  1. app.py +5 -8
  2. tools/file_reader.py +14 -4
app.py CHANGED
@@ -42,17 +42,15 @@ class ToolUsingAgent:
42
 
43
  elif "attached" in question_lower or "file" in question_lower:
44
  if task_id:
45
- file_content = self.read_file_tool.run(task_id)
46
  prompt = f"""
47
- You are a data analyst. Based on the following file content, answer the question exactly as asked, without extra text or explanations.
48
 
49
- Here is the file data:
50
- {file_content}
51
 
52
  Here is the question:
53
  {question}
54
-
55
- Only return the final answer, formatted exactly as required (e.g., number with 2 decimal places if asked).
56
  """
57
  completion = self.client.chat.completions.create(
58
  model=self.model,
@@ -65,8 +63,7 @@ class ToolUsingAgent:
65
  return "Please provide a valid task_id to read the attached file."
66
  else:
67
  prompt = f"""You are a helpful assistant answering GAIA benchmark questions.
68
- Return ONLY the final answer, without any explanation, extra text, or formatting.
69
- Do NOT include phrases like "the answer is", "here is", or any other words.
70
 
71
  If the answer is a list, return it exactly as requested:
72
  - For a comma-separated list: return items like `item1, item2, item3` with NO extra text.
 
42
 
43
  elif "attached" in question_lower or "file" in question_lower:
44
  if task_id:
45
+ file_summary = self.file_reader.run(task_id)
46
  prompt = f"""
47
+ You are a data analyst. Based on the following summarized file content, answer the question **exactly as asked**. Return only the final answer, with no explanations, no extra text, and in the required format..
48
 
49
+ File Summary:
50
+ {file_summary}
51
 
52
  Here is the question:
53
  {question}
 
 
54
  """
55
  completion = self.client.chat.completions.create(
56
  model=self.model,
 
63
  return "Please provide a valid task_id to read the attached file."
64
  else:
65
  prompt = f"""You are a helpful assistant answering GAIA benchmark questions.
66
+ Return ONLY the answer in the required format. Do NOT include extra text, explanations, or units unless explicitly asked.
 
67
 
68
  If the answer is a list, return it exactly as requested:
69
  - For a comma-separated list: return items like `item1, item2, item3` with NO extra text.
tools/file_reader.py CHANGED
@@ -12,19 +12,29 @@ def read_file(task_id: str) -> str:
12
  response.raise_for_status()
13
 
14
  content_type = response.headers.get("Content-Type", "")
15
- if "application/vnd.ms-excel" in content_type or "spreadsheet" in content_type:
 
 
16
  df = pd.read_excel(BytesIO(response.content))
17
- return df.to_csv(index=False)
18
  elif "csv" in content_type:
19
- return response.text
20
  else:
21
  return response.text
 
 
 
 
 
 
 
 
 
22
  except Exception as e:
23
  return f"[FileReader Error: {e}]"
24
 
25
  read_file_tool = Tool.from_function(
26
  name="read_file",
27
- description="Fetch and read a file from the GAIA API using task_id",
28
  func=read_file
29
  )
30
 
 
12
  response.raise_for_status()
13
 
14
  content_type = response.headers.get("Content-Type", "")
15
+
16
+ # Handle Excel/CSV files
17
+ if "spreadsheet" in content_type or "excel" in content_type:
18
  df = pd.read_excel(BytesIO(response.content))
 
19
  elif "csv" in content_type:
20
+ df = pd.read_csv(BytesIO(response.content))
21
  else:
22
  return response.text
23
+
24
+ # Filter: Only first 10 rows and 5 columns max
25
+ df = df.iloc[:10, :5]
26
+
27
+ # Optionally, return only column names and few rows
28
+ summary = df.head(10).to_csv(index=False)
29
+
30
+ return summary
31
+
32
  except Exception as e:
33
  return f"[FileReader Error: {e}]"
34
 
35
  read_file_tool = Tool.from_function(
36
  name="read_file",
37
+ description="Fetch and summarize a file from the GAIA API using task_id",
38
  func=read_file
39
  )
40