BenjaminKaindu0506 commited on
Commit
4b87506
·
verified ·
1 Parent(s): 403daa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -14
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, Tool, tool, VisitWebpageTool
7
 
8
 
9
  # (Keep Constants as is)
@@ -87,18 +87,58 @@ class BasicAgent:
87
  #description="Analyses images to locate and describe objects in them.",
88
  #trust_remote_code=True,
89
  #)
90
- """errors I get:
91
- - Error initializing agent: 'type'
92
- An extra system prompt:
93
- instructions=(
94
- "Answer with only the final answer value no explanation, "
95
- "no 'FINAL ANSWER' prefix, no extra formatting. "
96
- "If the question references a file, first call fetch_task_file "
97
- "with the given task_id to download it, then use the appropriate "
98
- "tool (read_spreadsheet for tables, image_analyser for images) "
99
- "to inspect it before answering. Use DuckDuckGoSearchTool only "
100
- "when the question needs current or external information."
101
- ),"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  pdf_tool = load_tool(
103
  "matterattetatte/pdf-upload-extractor-tool",
104
  trust_remote_code = True
@@ -115,7 +155,7 @@ class BasicAgent:
115
  #image_analysis_tool,
116
  ],
117
  model=InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
118
- instructions = "If the question includes a task_id and mentions a file, call fetch_task_file first; route YouTube URLs to get_youtube_transcript, other URLs to visit_webpage, PDFs to pdf_tool, and spreadsheets to read_spreadsheet, using web_search only when no URL or file is given,then respond with only the exact final answer value, no explanation, no prefix.",
119
  max_steps=20,
120
  )
121
  #answering questions
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, Tool, tool, VisitWebpageTool, load_tool
7
 
8
 
9
  # (Keep Constants as is)
 
87
  #description="Analyses images to locate and describe objects in them.",
88
  #trust_remote_code=True,
89
  #)
90
+ custom_prompt = """
91
+ You are a research agent solving GAIA benchmark questions. You must be
92
+ precise, because answers are graded by EXACT STRING MATCH against a ground
93
+ truth — no extra words, no units unless explicitly asked, no restating the
94
+ question, no "FINAL ANSWER:" prefix, no explanation in the final output.
95
+
96
+ Work in a strict Thought / Action / Observation cycle for every step:
97
+ - Thought: reason briefly about what you know, what's missing, and which
98
+ single tool call gets you closer to the answer.
99
+ - Action: call exactly one tool with the specific input it needs.
100
+ - Observation: read the tool's output carefully before your next Thought.
101
+ Never guess an answer without an Observation to support it. If a tool
102
+ returns nothing useful, change your query or try a different tool rather
103
+ than repeating the same call.
104
+
105
+ TOOL SELECTION RULES — check in this order for every question:
106
+
107
+ 1. FILES: If the question includes a task_id and references a file, image,
108
+ spreadsheet, or document, your first Action must be fetch_task_file(task_id)
109
+ to download it before anything else.
110
+ - If the downloaded file ends in .csv or .xlsx: use read_spreadsheet to
111
+ inspect it as a table before reasoning about numbers or entries.
112
+ - If it ends in .pdf: use pdf_tool to extract its text.
113
+ - If it's an image: describe what you need to find, and reason only from
114
+ details you can verify — do not invent visual details you cannot confirm.
115
+
116
+ 2. YOUTUBE: If the question contains a youtube.com or youtu.be URL, use
117
+ get_youtube_transcript on that URL. Read the full transcript before
118
+ answering — do not assume content from the title alone.
119
+
120
+ 3. OTHER URLS: If the question contains any other URL, use visit_webpage on
121
+ it directly. Do not web_search for a page you were already given a link to.
122
+
123
+ 4. GENERAL KNOWLEDGE OR CURRENT INFO: If there is no file and no URL, or the
124
+ given source doesn't contain the answer, use web_search with a short,
125
+ specific query (not the full question text verbatim). If the first
126
+ result set doesn't answer it, refine the query — try alternate terms,
127
+ dates, or named entities — before giving up.
128
+
129
+ 5. MATH / COUNTING / DATA MANIPULATION: Do these directly in Python code
130
+ within your Action step rather than trying to compute them mentally or
131
+ estimate them.
132
+
133
+ ANSWER FORMAT:
134
+ - Once you have verified evidence (not assumption) for the answer, stop.
135
+ - Return only the answer itself: a number, a name, a short string, or a
136
+ list, in the exact form the question asks for (e.g. "3" not "three
137
+ albums", "Paris" not "The city is Paris").
138
+ - If after reasonable effort across tools you cannot find a verified
139
+ answer, return your best-supported guess rather than an empty or vague
140
+ response — GAIA has no partial credit for admitting uncertainty.
141
+ """
142
  pdf_tool = load_tool(
143
  "matterattetatte/pdf-upload-extractor-tool",
144
  trust_remote_code = True
 
155
  #image_analysis_tool,
156
  ],
157
  model=InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
158
+ instructions = custom_prompt+"If the question includes a task_id and mentions a file, call fetch_task_file first; route YouTube URLs to get_youtube_transcript, other URLs to visit_webpage, PDFs to pdf_tool, and spreadsheets to read_spreadsheet, using web_search only when no URL or file is given,then respond with only the exact final answer value, no explanation, no prefix.",
159
  max_steps=20,
160
  )
161
  #answering questions