Spaces:
Sleeping
Sleeping
Corrected agent block
Browse files- Added smolagent WebSearchTool
- updated requirements.txt with smolagents[toolkit]
- updated GAIA benchmark specific promt
app.py
CHANGED
|
@@ -3,8 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from
|
| 7 |
-
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -12,43 +12,47 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
|
| 15 |
-
|
| 16 |
-
def web_search(self, query: str) -> str:
|
| 17 |
-
"""A tool that does web search
|
| 18 |
-
query: The first argument -> What to search
|
| 19 |
-
|
| 20 |
-
"""
|
| 21 |
-
search_tool = DuckDuckGoSearchTool()
|
| 22 |
-
st_response = search_tool(query)
|
| 23 |
-
return st_response
|
| 24 |
-
|
| 25 |
class BasicAgent:
|
| 26 |
def __init__(self):
|
| 27 |
print("Srj's Agent initialized.")
|
| 28 |
-
self.
|
|
|
|
| 29 |
|
| 30 |
def __call__(self, question: str) -> str:
|
| 31 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
Capital of France? → Paris
|
| 40 |
-
2024 Olympics city? → Paris
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
output = self.
|
| 44 |
-
|
| 45 |
-
{"role":"User","content":prompt}
|
| 46 |
-
],
|
| 47 |
-
stream= False,
|
| 48 |
-
max_tokens= 20,
|
| 49 |
-
extra_body={"thinking":{"type":'disabled'}}
|
| 50 |
-
)
|
| 51 |
-
return output.choices[0].message.content.strip()
|
| 52 |
|
| 53 |
|
| 54 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel
|
| 7 |
+
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
print("Srj's Agent initialized.")
|
| 18 |
+
self.model = InferenceClientModel(model= "moonshotai/Kimi-K2.5", token = os.environ.get("HF_TOKEN"))
|
| 19 |
+
self.agent = CodeAgent(tools=[WebSearchTool()], model=self.model, stream_outputs=False, max_tokens=20)
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 23 |
+
prompt = f"""You are an expert GAIA benchmark agent. Your job is to solve Level 1 GAIA questions with PERFECT formatting.
|
| 24 |
+
|
| 25 |
+
CRITICAL RULES (Follow EXACTLY):
|
| 26 |
+
1. Answer with ONLY the final answer - NO "Final Answer:", NO reasoning, NO explanation
|
| 27 |
+
2. Use exact format: number, city name, short phrase, or comma-separated list
|
| 28 |
+
3. NO units unless asked ($, %, etc.)
|
| 29 |
+
4. NO articles ("the", "a", "an")
|
| 30 |
+
5. Spell out numbers in words when asked for text
|
| 31 |
+
6. For cities: full name, no abbreviations (Los Angeles, not LA)
|
| 32 |
+
|
| 33 |
+
GAIA LEVEL 1 KNOWLEDGE (Your memory):
|
| 34 |
+
- 2024 Summer Olympics: Paris, France (July 26-Aug 11)
|
| 35 |
+
- France capital: Paris (pop ~2 million city proper)
|
| 36 |
+
- USA capital: Washington, D.C.
|
| 37 |
+
- UK capital: London
|
| 38 |
+
- Germany capital: Berlin
|
| 39 |
+
- Japan capital: Tokyo
|
| 40 |
+
- Basic math: 15×3=45, 100/4=25, etc.
|
| 41 |
+
|
| 42 |
+
FORMAT EXAMPLES (Copy these exactly):
|
| 43 |
Capital of France? → Paris
|
| 44 |
+
2024 Olympics host city? → Paris
|
| 45 |
+
Capital of Japan? → Tokyo
|
| 46 |
+
15 × 3? → 45
|
| 47 |
+
Paris population (millions)? → 2 million
|
| 48 |
+
USA capital? → Washington, D.C.
|
| 49 |
+
|
| 50 |
+
Question: {question}
|
| 51 |
+
|
| 52 |
+
Respond with ONLY the final answer."""
|
| 53 |
|
| 54 |
+
output = self.agent.run(prompt)
|
| 55 |
+
return output.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|