2MoOn24mOoN4 commited on
Commit
403840c
·
verified ·
1 Parent(s): 81917a3

Create agent.py

Browse files
Files changed (1) hide show
  1. agent.py +46 -0
agent.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, tool
3
+
4
+ #========Tools========#
5
+ @tool
6
+ def multiply(a: int, b: int) -> int:
7
+ return a * b
8
+ @tool
9
+ def add(a: int, b: int) -> int:
10
+ return a + b
11
+ @tool
12
+ def subtract(a: int, b: int) -> int:
13
+ return a - b
14
+ @tool
15
+ def divide(a: int, b: int) -> int:
16
+ if b == 0:
17
+ raise ValueError("Cannot divide by zero.")
18
+ return a / b
19
+ @tool
20
+ def modulus(a: int, b: int) -> int:
21
+ return a % b
22
+ search_tool=DuckDuckGoSearchTool()
23
+
24
+ #=======Agent========#
25
+ model = InferenceClientModel()
26
+ agent = CodeAgent(
27
+ tools=[
28
+ multiply,
29
+ add,
30
+ subtract,
31
+ divide,
32
+ modulus,
33
+ search_tool],
34
+ model = model,
35
+ add_base_tools=True,
36
+ planning_interval=3
37
+ )
38
+ with open("Q20.json", "r") as f:
39
+ tasks = json.load(f)
40
+
41
+ for task in tasks:
42
+ task_id = task["task_id"]
43
+ question = task["question"]
44
+ file_name = task["file_name"]
45
+ answer = agent.run(question)
46
+ print(f"task_id: {task_id},submitted_answer: {answer}")