lam-ho commited on
Commit
19b9935
·
verified ·
1 Parent(s): b5492dd

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +105 -38
agent.py CHANGED
@@ -1,68 +1,135 @@
1
- from smolagents import HfApiModel, CodeAgent, DuckDuckGoSearchTool, WikipediaSearchTool, tool
2
 
3
 
4
- @tool
5
- def add(a: int, b: int) -> int:
6
- """
7
  This tool adds two integers together and returns an integer.
8
 
9
  Args:
10
  a: first int
11
  b: second int
12
- """
13
- return a + b
14
-
15
- @tool
16
- def subtract(a: int, b: int) -> int:
17
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  This tool subtracts two integers and returns an integer.
19
 
20
  Args:
21
  a: first int
22
  b: second int
23
- """
24
- return a - b
25
-
26
- @tool
27
- def multiply(a: int, b: int) -> int:
28
- """
29
- This tool multiplies two integers together and returns an integer.
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  Args:
32
  a: first int
33
  b: second int
34
- """
35
- return a * b
36
-
37
- @tool
38
- def divide(a: int, b: int) -> int:
39
- """
40
- This tool divides two integers together and returns a float.
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  Args:
43
  a: first int
44
  b: second int
45
- """
46
- if b == 0:
47
- raise ValueError("Cannot divide by zero.")
48
- return a / b
49
-
50
- def modulo(a: int, b: int) -> float:
51
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  This tool returns the modulus of two integers
53
 
54
  Args:
55
  a: first int
56
  b: second int
57
- """
58
- return a % b
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  tools=[
61
- add,
62
- subtract,
63
- multiply,
64
- divide,
65
- modulo,
66
  DuckDuckGoSearchTool(),
67
  WikipediaSearchTool()
68
  ]
 
1
+ from smolagents import HfApiModel, CodeAgent, DuckDuckGoSearchTool, WikipediaSearchTool, Tool
2
 
3
 
4
+ class add(Tool):
5
+ name = "add"
6
+ description = """
7
  This tool adds two integers together and returns an integer.
8
 
9
  Args:
10
  a: first int
11
  b: second int
12
+ """
13
+ inputs = {
14
+ "a":{
15
+ "type":"int",
16
+ "description":"first int"
17
+ },
18
+ "b":{
19
+ "type":"int",
20
+ "description":"second int"
21
+ }
22
+ }
23
+ output_type = "int"
24
+
25
+ def forward(self, a: int, b: int):
26
+ return a + b
27
+
28
+
29
+ class subtract(Tool):
30
+ name = "subtract"
31
+ description = """
32
  This tool subtracts two integers and returns an integer.
33
 
34
  Args:
35
  a: first int
36
  b: second int
37
+ """
38
+ inputs = {
39
+ "a":{
40
+ "type":"int",
41
+ "description":"first int"
42
+ },
43
+ "b":{
44
+ "type":"int",
45
+ "description":"second int"
46
+ }
47
+ }
48
+ output_type = "int"
49
+
50
+ def forward(self, a: int, b: int):
51
+ return a - b
52
+
53
+ class multiply(Tool):
54
+ name = "multiply"
55
+ description = """
56
+ This tool multiplies two integers and returns an integer.
57
 
58
  Args:
59
  a: first int
60
  b: second int
61
+ """
62
+ inputs = {
63
+ "a":{
64
+ "type":"int",
65
+ "description":"first int"
66
+ },
67
+ "b":{
68
+ "type":"int",
69
+ "description":"second int"
70
+ }
71
+ }
72
+ output_type = "int"
73
+
74
+ def forward(self, a: int, b: int):
75
+ return a * b
76
+
77
+ class divide(Tool):
78
+ name = "divide"
79
+ description = """
80
+ This tool divides two integers and returns an integer.
81
 
82
  Args:
83
  a: first int
84
  b: second int
85
+ """
86
+ inputs = {
87
+ "a":{
88
+ "type":"int",
89
+ "description":"first int"
90
+ },
91
+ "b":{
92
+ "type":"int",
93
+ "description":"second int"
94
+ }
95
+ }
96
+ output_type = "int"
97
+
98
+ def forward(self, a: int, b: int):
99
+ if b == 0:
100
+ raise ValueError("Cannot divide by zero.")
101
+ return a / b
102
+
103
+ class modulo(Tool):
104
+ name = "modulo"
105
+ description = """
106
  This tool returns the modulus of two integers
107
 
108
  Args:
109
  a: first int
110
  b: second int
111
+ """
112
+ inputs = {
113
+ "a":{
114
+ "type":"int",
115
+ "description":"first int"
116
+ },
117
+ "b":{
118
+ "type":"int",
119
+ "description":"second int"
120
+ }
121
+ }
122
+ output_type = "int"
123
+
124
+ def forward(self, a: int, b: int):
125
+ return a % b
126
 
127
  tools=[
128
+ add(),
129
+ subtract(),
130
+ multiply(),
131
+ divide(),
132
+ modulo(),
133
  DuckDuckGoSearchTool(),
134
  WikipediaSearchTool()
135
  ]