Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,49 +1,29 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
from smolagents import Agent
|
| 4 |
-
from smolagents.core.task import Task
|
| 5 |
-
from mistral_hf_wrapper import HuggingFaceModel
|
| 6 |
|
| 7 |
-
|
| 8 |
-
from
|
| 9 |
-
|
| 10 |
-
classifier_tool,
|
| 11 |
-
content_retriever_tool,
|
| 12 |
-
get_attachments_tool,
|
| 13 |
-
google_search_tools,
|
| 14 |
-
speech_recognition_tool,
|
| 15 |
-
youtube_video_tool,
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
with open(path, "r", encoding="utf-8") as f:
|
| 21 |
-
return [Task(**json.loads(line)) for line in f]
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
classifier_tool.ClassifierTool(),
|
| 32 |
-
content_retriever_tool.ContentRetrieverTool(),
|
| 33 |
-
get_attachments_tool.GetAttachmentTool(),
|
| 34 |
-
google_search_tools.GoogleSearchTool(),
|
| 35 |
-
google_search_tools.GoogleSiteSearchTool(),
|
| 36 |
-
speech_recognition_tool.SpeechRecognitionTool(),
|
| 37 |
-
youtube_video_tool.YouTubeVideoTool(),
|
| 38 |
-
]
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
system_message="You are a helpful AI agent solving GAIA benchmark tasks. Only return the answer, no extra explanation."
|
| 45 |
-
)
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
from tools import TOOLS
|
| 5 |
+
from metadata import load_metadata
|
| 6 |
+
from mistral_inference import query_mistral
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
API_URL = os.getenv("HF_MISTRAL_URL")
|
| 9 |
+
API_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
HEADERS = {
|
| 12 |
+
"Authorization": f"Bearer {API_TOKEN}",
|
| 13 |
+
"Content-Type": "application/json"
|
| 14 |
+
}
|
| 15 |
|
| 16 |
+
# Load all tasks from metadata.jsonl
|
| 17 |
+
def load_tasks():
|
| 18 |
+
return load_metadata("metadata.jsonl")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# Solve a single task
|
| 21 |
+
def solve_task(task, tools=TOOLS):
|
| 22 |
+
system_prompt = "You are a helpful agent. Use reasoning, tools if needed, and return the answer only."
|
| 23 |
+
user_prompt = task["question"]
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
response = query_mistral(API_URL, HEADERS, system_prompt, user_prompt)
|
| 26 |
+
return {
|
| 27 |
+
"task_id": task["question_id"],
|
| 28 |
+
"submitted_answer": response.strip()
|
| 29 |
+
}
|