Spaces:
Sleeping
Sleeping
Commit
·
edab6f8
1
Parent(s):
8c77163
modified gitignore
Browse files- app.py +2 -11
- gaia_agent.py +16 -23
- gaia_tools.py +22 -2
- requirements.txt +2 -1
app.py
CHANGED
@@ -12,17 +12,6 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
12 |
# To check if we are running locally
|
13 |
running_on_hf = False
|
14 |
|
15 |
-
# --- Basic Agent Definition ---
|
16 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
17 |
-
# class BasicAgent:
|
18 |
-
# def __init__(self):
|
19 |
-
# print("BasicAgent initialized.")
|
20 |
-
# def __call__(self, question: str) -> str:
|
21 |
-
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
22 |
-
# fixed_answer = "This is a default answer."
|
23 |
-
# print(f"Agent returning fixed answer: {fixed_answer}")
|
24 |
-
# return fixed_answer
|
25 |
-
|
26 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
27 |
"""
|
28 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
@@ -89,6 +78,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
89 |
continue
|
90 |
try:
|
91 |
submitted_answer = agent(question_text)
|
|
|
92 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
93 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
94 |
except Exception as e:
|
@@ -156,6 +146,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
156 |
# --- Build Gradio Interface using Blocks ---
|
157 |
with gr.Blocks() as demo:
|
158 |
gr.Markdown("# GAIA Agent")
|
|
|
159 |
gr.Markdown(
|
160 |
"""
|
161 |
**Instructions:**
|
|
|
12 |
# To check if we are running locally
|
13 |
running_on_hf = False
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
16 |
"""
|
17 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
78 |
continue
|
79 |
try:
|
80 |
submitted_answer = agent(question_text)
|
81 |
+
print(type(submitted_answer))
|
82 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
83 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
84 |
except Exception as e:
|
|
|
146 |
# --- Build Gradio Interface using Blocks ---
|
147 |
with gr.Blocks() as demo:
|
148 |
gr.Markdown("# GAIA Agent")
|
149 |
+
gr.Image(value="assets/AI_Programmer.png")
|
150 |
gr.Markdown(
|
151 |
"""
|
152 |
**Instructions:**
|
gaia_agent.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
from smolagents import InferenceClientModel, ToolCallingAgent
|
3 |
from smolagents import DuckDuckGoSearchTool, VisitWebpageTool
|
|
|
4 |
|
5 |
class GaiaAgent:
|
6 |
def __init__(self):
|
@@ -13,7 +14,8 @@ class GaiaAgent:
|
|
13 |
|
14 |
self.tools = [
|
15 |
DuckDuckGoSearchTool(),
|
16 |
-
VisitWebpageTool()
|
|
|
17 |
]
|
18 |
|
19 |
self.agent = ToolCallingAgent(
|
@@ -24,33 +26,24 @@ class GaiaAgent:
|
|
24 |
def __call__(self, question: str) -> str:
|
25 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
26 |
|
27 |
-
prompt = f"""
|
|
|
28 |
|
29 |
-
|
30 |
-
1. Return only the exact requested answered: no explanation and no reasoning.
|
31 |
-
2. For yes/no questions, return exactly "Yes" or "No".
|
32 |
-
3. For dates, use the exact format requested.
|
33 |
-
4. For numbers, use the exact number, no other format.
|
34 |
-
5. For names, use the exact name as found in sources.
|
35 |
-
6. If the question has an associated file, download the file first using the task ID
|
36 |
|
37 |
-
|
38 |
-
- "42"
|
39 |
-
- "Arturo Nunez"
|
40 |
-
- "Yes"
|
41 |
-
- "October 5, 2001"
|
42 |
-
- "Buenos Aires"
|
43 |
|
44 |
-
|
45 |
-
Only return the exact answer.
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
# ]
|
54 |
|
55 |
try:
|
56 |
result = self.agent.run(prompt)
|
|
|
1 |
import os
|
2 |
from smolagents import InferenceClientModel, ToolCallingAgent
|
3 |
from smolagents import DuckDuckGoSearchTool, VisitWebpageTool
|
4 |
+
from gaia_tools import RunPythonFileTool
|
5 |
|
6 |
class GaiaAgent:
|
7 |
def __init__(self):
|
|
|
14 |
|
15 |
self.tools = [
|
16 |
DuckDuckGoSearchTool(),
|
17 |
+
VisitWebpageTool(),
|
18 |
+
RunPythonFileTool
|
19 |
]
|
20 |
|
21 |
self.agent = ToolCallingAgent(
|
|
|
26 |
def __call__(self, question: str) -> str:
|
27 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
28 |
|
29 |
+
prompt = f"""
|
30 |
+
You are a helpful agent that must provide exact answers to questions. Do not explain or format your answer in any way.
|
31 |
|
32 |
+
If a question can be solved with reasoning, riddles, puzzles, or reversing text — solve it yourself.
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
If the query involves a known Wikipedia page, use VisitWebpageTool to open it and extract the needed info directly. Do not rely on summaries.
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
If the query requires the execution of python code, make sure the code is valid before trying to execute it.
|
|
|
37 |
|
38 |
+
Question: {question}
|
39 |
+
|
40 |
+
Rules:
|
41 |
+
- If the question is reversed, reverse it and solve it.
|
42 |
+
- If the answer is a single word, output only that word.
|
43 |
+
- Do not say anything else.
|
44 |
|
45 |
+
Only output the final answer.
|
46 |
+
"""
|
|
|
47 |
|
48 |
try:
|
49 |
result = self.agent.run(prompt)
|
gaia_tools.py
CHANGED
@@ -1,2 +1,22 @@
|
|
1 |
-
from smolagents import
|
2 |
-
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import PythonInterpreterTool, tool
|
2 |
+
import requests
|
3 |
+
|
4 |
+
@tool
|
5 |
+
def RunPythonFileTool(file_path: str) -> str:
|
6 |
+
"""
|
7 |
+
Executes a Python script loaded from the specified path using the PythonInterpreterTool.
|
8 |
+
|
9 |
+
Args:
|
10 |
+
file_path (str): The full path to the python (.py) file containing the Python code.
|
11 |
+
|
12 |
+
Returns:
|
13 |
+
str: The output produced by the code execution, or an error code if it fails.
|
14 |
+
"""
|
15 |
+
try:
|
16 |
+
with open(file_path, "r") as f:
|
17 |
+
code = f.read()
|
18 |
+
interpreter = PythonInterpreterTool()
|
19 |
+
result = interpreter.run({"code": code})
|
20 |
+
return result
|
21 |
+
except Exception as e:
|
22 |
+
return f"Execution failed: {e}"
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
gradio[oauth]
|
2 |
requests
|
3 |
smolagents
|
4 |
-
duckduckgo-search
|
|
|
|
1 |
gradio[oauth]
|
2 |
requests
|
3 |
smolagents
|
4 |
+
duckduckgo-search
|
5 |
+
openai
|