FD900 commited on
Commit
368de35
·
verified ·
1 Parent(s): 8c0dedc

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +13 -9
agent.py CHANGED
@@ -1,7 +1,10 @@
1
  import json
2
  from pathlib import Path
3
- from smolagents import Agent, Task
 
4
  from mistral_hf_wrapper import HuggingFaceModel
 
 
5
  from tools import (
6
  chess_tools,
7
  classifier_tool,
@@ -12,19 +15,18 @@ from tools import (
12
  youtube_video_tool,
13
  )
14
 
 
15
  def load_tasks(path: str = "metadata.jsonl") -> list[Task]:
16
- tasks = []
17
  with open(path, "r", encoding="utf-8") as f:
18
- for line in f:
19
- task_dict = json.loads(line.strip())
20
- tasks.append(Task(**task_dict))
21
- return tasks
22
 
 
23
  model = HuggingFaceModel(
24
  endpoint_url="https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
25
  )
26
 
27
- toolset = [
 
28
  chess_tools.ImageToChessBoardFENTool(),
29
  classifier_tool.ClassifierTool(),
30
  content_retriever_tool.ContentRetrieverTool(),
@@ -35,11 +37,13 @@ toolset = [
35
  youtube_video_tool.YouTubeVideoTool(),
36
  ]
37
 
 
38
  agent = Agent(
39
  model=model,
40
- tools=toolset,
41
- system_message="You are a helpful assistant solving GAIA benchmark tasks. Return only the final answer, nothing else."
42
  )
43
 
 
44
  def solve_task(task: Task) -> str:
45
  return agent.run(task.question, task_id=task.task_id)
 
1
  import json
2
  from pathlib import Path
3
+ from smolagents.core.agent import Agent
4
+ from smolagents.core.task import Task
5
  from mistral_hf_wrapper import HuggingFaceModel
6
+
7
+ # Import tools
8
  from tools import (
9
  chess_tools,
10
  classifier_tool,
 
15
  youtube_video_tool,
16
  )
17
 
18
+ # Load GAIA task list from metadata.jsonl
19
  def load_tasks(path: str = "metadata.jsonl") -> list[Task]:
 
20
  with open(path, "r", encoding="utf-8") as f:
21
+ return [Task(**json.loads(line)) for line in f]
 
 
 
22
 
23
+ # Configure Mistral Inference Endpoint wrapper
24
  model = HuggingFaceModel(
25
  endpoint_url="https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
26
  )
27
 
28
+ # List of tool instances
29
+ tools = [
30
  chess_tools.ImageToChessBoardFENTool(),
31
  classifier_tool.ClassifierTool(),
32
  content_retriever_tool.ContentRetrieverTool(),
 
37
  youtube_video_tool.YouTubeVideoTool(),
38
  ]
39
 
40
+ # Build the agent
41
  agent = Agent(
42
  model=model,
43
+ tools=tools,
44
+ system_message="You are a helpful AI agent solving GAIA benchmark tasks. Only return the answer, no extra explanation."
45
  )
46
 
47
+ # Core solve function
48
  def solve_task(task: Task) -> str:
49
  return agent.run(task.question, task_id=task.task_id)