Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -20,6 +20,13 @@ load_dotenv()
|
|
| 20 |
DEFAULT_SCORING_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 21 |
DEFAULT_GEMINI_MODEL_ID = os.getenv("GEMINI_MODEL_ID", "gemini/gemini-2.5-flash")
|
| 22 |
GEMINI_OPENAI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai/"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
GAIA_OUTPUT_PROMPT = """
|
| 24 |
You are an evaluation-grade GAIA benchmark AI assistant. Your execution must be perfectly precise and highly deterministic. Your sole purpose is to isolate and output the exact, minimal final answer.
|
| 25 |
|
|
@@ -122,7 +129,7 @@ def _decode_text_bytes(payload: bytes) -> str:
|
|
| 122 |
|
| 123 |
|
| 124 |
def _download_task_file(task_id: str) -> tuple[bytes, str]:
|
| 125 |
-
response =
|
| 126 |
response.raise_for_status()
|
| 127 |
content_type = response.headers.get("content-type", "application/octet-stream")
|
| 128 |
return response.content, content_type
|
|
@@ -366,7 +373,7 @@ class WikiTitleFinder(Tool):
|
|
| 366 |
output_type = "string"
|
| 367 |
|
| 368 |
def forward(self, query: str) -> str:
|
| 369 |
-
response =
|
| 370 |
"https://en.wikipedia.org/w/api.php",
|
| 371 |
params={
|
| 372 |
"action": "query",
|
|
@@ -374,6 +381,7 @@ class WikiTitleFinder(Tool):
|
|
| 374 |
"srsearch": query,
|
| 375 |
"srlimit": 5,
|
| 376 |
"format": "json",
|
|
|
|
| 377 |
},
|
| 378 |
timeout=20,
|
| 379 |
)
|
|
@@ -396,7 +404,7 @@ class WikiContentFetcher(Tool):
|
|
| 396 |
output_type = "string"
|
| 397 |
|
| 398 |
def forward(self, page_title: str) -> str:
|
| 399 |
-
response =
|
| 400 |
"https://en.wikipedia.org/w/api.php",
|
| 401 |
params={
|
| 402 |
"action": "query",
|
|
@@ -405,6 +413,7 @@ class WikiContentFetcher(Tool):
|
|
| 405 |
"redirects": 1,
|
| 406 |
"titles": page_title,
|
| 407 |
"format": "json",
|
|
|
|
| 408 |
},
|
| 409 |
timeout=20,
|
| 410 |
)
|
|
@@ -419,7 +428,7 @@ class WikiContentFetcher(Tool):
|
|
| 419 |
|
| 420 |
class GoogleSearchTool(Tool):
|
| 421 |
name = "google_search"
|
| 422 |
-
description = "Search the live web
|
| 423 |
inputs = {
|
| 424 |
"query": {
|
| 425 |
"type": "string",
|
|
@@ -429,16 +438,7 @@ class GoogleSearchTool(Tool):
|
|
| 429 |
output_type = "string"
|
| 430 |
|
| 431 |
def forward(self, query: str) -> str:
|
| 432 |
-
|
| 433 |
-
response = _genai_client().models.generate_content(
|
| 434 |
-
model=_normalize_model_id(),
|
| 435 |
-
contents=query,
|
| 436 |
-
config=genai_types.GenerateContentConfig(
|
| 437 |
-
temperature=0,
|
| 438 |
-
tools=[grounding_tool],
|
| 439 |
-
),
|
| 440 |
-
)
|
| 441 |
-
return _extract_text(response)
|
| 442 |
|
| 443 |
|
| 444 |
class FileAttachmentQueryTool(Tool):
|
|
|
|
| 20 |
DEFAULT_SCORING_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 21 |
DEFAULT_GEMINI_MODEL_ID = os.getenv("GEMINI_MODEL_ID", "gemini/gemini-2.5-flash")
|
| 22 |
GEMINI_OPENAI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta/openai/"
|
| 23 |
+
HTTP_SESSION = requests.Session()
|
| 24 |
+
HTTP_SESSION.headers.update(
|
| 25 |
+
{
|
| 26 |
+
"User-Agent": "DukeDDrake1999-AgentCourse/1.0 (Hugging Face Space benchmark client)",
|
| 27 |
+
"Accept": "application/json, text/plain, */*",
|
| 28 |
+
}
|
| 29 |
+
)
|
| 30 |
GAIA_OUTPUT_PROMPT = """
|
| 31 |
You are an evaluation-grade GAIA benchmark AI assistant. Your execution must be perfectly precise and highly deterministic. Your sole purpose is to isolate and output the exact, minimal final answer.
|
| 32 |
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
def _download_task_file(task_id: str) -> tuple[bytes, str]:
|
| 132 |
+
response = HTTP_SESSION.get(f"{DEFAULT_SCORING_API_URL}/files/{task_id}", timeout=60)
|
| 133 |
response.raise_for_status()
|
| 134 |
content_type = response.headers.get("content-type", "application/octet-stream")
|
| 135 |
return response.content, content_type
|
|
|
|
| 373 |
output_type = "string"
|
| 374 |
|
| 375 |
def forward(self, query: str) -> str:
|
| 376 |
+
response = HTTP_SESSION.get(
|
| 377 |
"https://en.wikipedia.org/w/api.php",
|
| 378 |
params={
|
| 379 |
"action": "query",
|
|
|
|
| 381 |
"srsearch": query,
|
| 382 |
"srlimit": 5,
|
| 383 |
"format": "json",
|
| 384 |
+
"origin": "*",
|
| 385 |
},
|
| 386 |
timeout=20,
|
| 387 |
)
|
|
|
|
| 404 |
output_type = "string"
|
| 405 |
|
| 406 |
def forward(self, page_title: str) -> str:
|
| 407 |
+
response = HTTP_SESSION.get(
|
| 408 |
"https://en.wikipedia.org/w/api.php",
|
| 409 |
params={
|
| 410 |
"action": "query",
|
|
|
|
| 413 |
"redirects": 1,
|
| 414 |
"titles": page_title,
|
| 415 |
"format": "json",
|
| 416 |
+
"origin": "*",
|
| 417 |
},
|
| 418 |
timeout=20,
|
| 419 |
)
|
|
|
|
| 428 |
|
| 429 |
class GoogleSearchTool(Tool):
|
| 430 |
name = "google_search"
|
| 431 |
+
description = "Search the live web and return a concise result."
|
| 432 |
inputs = {
|
| 433 |
"query": {
|
| 434 |
"type": "string",
|
|
|
|
| 438 |
output_type = "string"
|
| 439 |
|
| 440 |
def forward(self, query: str) -> str:
|
| 441 |
+
return DuckDuckGoSearchTool().forward(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
|
| 444 |
class FileAttachmentQueryTool(Tool):
|