Update app.py
Browse files
app.py
CHANGED
|
@@ -87,74 +87,34 @@ class BasicAgent:
|
|
| 87 |
#description="Analyses images to locate and describe objects in them.",
|
| 88 |
#trust_remote_code=True,
|
| 89 |
#)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
truth β no extra words, no units unless explicitly asked, no restating the
|
| 93 |
-
question, no "FINAL ANSWER:" prefix, no explanation in the final output.
|
| 94 |
-
|
| 95 |
-
Work in a strict Thought / Action / Observation cycle for every step:
|
| 96 |
-
- Thought: reason briefly about what you know, what's missing, and which
|
| 97 |
-
single tool call gets you closer to the answer.
|
| 98 |
-
- Action: call exactly one tool with the specific input it needs.
|
| 99 |
-
- Observation: read the tool's output carefully before your next Thought.
|
| 100 |
-
Never guess an answer without an Observation to support it. If a tool
|
| 101 |
-
returns nothing useful, change your query or try a different tool rather
|
| 102 |
-
than repeating the same call.
|
| 103 |
-
|
| 104 |
-
TOOL SELECTION RULES β check in this order for every question:
|
| 105 |
-
|
| 106 |
-
1. FILES: If the question includes a task_id and references a file, image,
|
| 107 |
-
spreadsheet, or document, your first Action must be fetch_task_file(task_id)
|
| 108 |
-
to download it before anything else.
|
| 109 |
-
- If the downloaded file ends in .csv or .xlsx: use read_spreadsheet to
|
| 110 |
-
inspect it as a table before reasoning about numbers or entries.
|
| 111 |
-
- If it ends in .pdf: use pdf_tool to extract its text.
|
| 112 |
-
- If it's an image: describe what you need to find, and reason only from
|
| 113 |
-
details you can verify β do not invent visual details you cannot confirm.
|
| 114 |
-
|
| 115 |
-
2. YOUTUBE: If the question contains a youtube.com or youtu.be URL, use
|
| 116 |
-
get_youtube_transcript on that URL. Read the full transcript before
|
| 117 |
-
answering β do not assume content from the title alone.
|
| 118 |
-
|
| 119 |
-
3. OTHER URLS: If the question contains any other URL, use visit_webpage on
|
| 120 |
-
it directly. Do not web_search for a page you were already given a link to.
|
| 121 |
-
|
| 122 |
-
4. GENERAL KNOWLEDGE OR CURRENT INFO: If there is no file and no URL, or the
|
| 123 |
-
given source doesn't contain the answer, use web_search with a short,
|
| 124 |
-
specific query (not the full question text verbatim). If the first
|
| 125 |
-
result set doesn't answer it, refine the query β try alternate terms,
|
| 126 |
-
dates, or named entities β before giving up.
|
| 127 |
-
|
| 128 |
-
5. MATH / COUNTING / DATA MANIPULATION: Do these directly in Python code
|
| 129 |
-
within your Action step rather than trying to compute them mentally or
|
| 130 |
-
estimate them.
|
| 131 |
-
|
| 132 |
-
ANSWER FORMAT:
|
| 133 |
-
- Once you have verified evidence (not assumption) for the answer, stop.
|
| 134 |
-
- Return only the answer itself: a number, a name, a short string, or a
|
| 135 |
-
list, in the exact form the question asks for (e.g. "3" not "three
|
| 136 |
-
albums", "Paris" not "The city is Paris").
|
| 137 |
-
- If after reasonable effort across tools you cannot find a verified
|
| 138 |
-
answer, return your best-supported guess rather than an empty or vague
|
| 139 |
-
response β GAIA has no partial credit for admitting uncertainty.
|
| 140 |
-
"""
|
| 141 |
-
pdf_tool = load_tool(
|
| 142 |
"matterattetatte/pdf-upload-extractor-tool",
|
| 143 |
trust_remote_code = True
|
| 144 |
-
)
|
| 145 |
self.agent = CodeAgent(
|
| 146 |
tools=[
|
| 147 |
DuckDuckGoSearchTool(),
|
| 148 |
VisitWebpageTool(),
|
| 149 |
-
pdf_tool,
|
| 150 |
fetch_task_file,
|
| 151 |
read_spreadsheet,
|
| 152 |
get_youtube_transcript,
|
| 153 |
#os.environ["HF_TOKEN"] = "hf_token",
|
| 154 |
#image_analysis_tool,
|
| 155 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
|
| 157 |
-
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.",
|
| 158 |
max_steps=20,
|
| 159 |
)
|
| 160 |
#answering questions
|
|
|
|
| 87 |
#description="Analyses images to locate and describe objects in them.",
|
| 88 |
#trust_remote_code=True,
|
| 89 |
#)
|
| 90 |
+
|
| 91 |
+
"""pdf_tool = load_tool(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
"matterattetatte/pdf-upload-extractor-tool",
|
| 93 |
trust_remote_code = True
|
| 94 |
+
)"""
|
| 95 |
self.agent = CodeAgent(
|
| 96 |
tools=[
|
| 97 |
DuckDuckGoSearchTool(),
|
| 98 |
VisitWebpageTool(),
|
| 99 |
+
#pdf_tool,
|
| 100 |
fetch_task_file,
|
| 101 |
read_spreadsheet,
|
| 102 |
get_youtube_transcript,
|
| 103 |
#os.environ["HF_TOKEN"] = "hf_token",
|
| 104 |
#image_analysis_tool,
|
| 105 |
],
|
| 106 |
+
additional_authorized_imports=[
|
| 107 |
+
"pypdf", # basic text extraction
|
| 108 |
+
"pdfplumber", # better for tables/layout inside PDFs
|
| 109 |
+
"fitz", # PyMuPDF β fast, handles images + text well
|
| 110 |
+
"io", # often needed for BytesIO when handling file bytes
|
| 111 |
+
"requests", # for fetch_task_file
|
| 112 |
+
"pandas", # for read_spreadsheet
|
| 113 |
+
"openpyxl", # backend pandas needs for .xlsx
|
| 114 |
+
"bs4", # for parsing HTML from VisitWebpageTool output if needed
|
| 115 |
+
]
|
| 116 |
model= InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct"),
|
| 117 |
+
#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.",
|
| 118 |
max_steps=20,
|
| 119 |
)
|
| 120 |
#answering questions
|