Update tools.py
Browse files
tools.py
CHANGED
@@ -104,43 +104,25 @@ class CalendarTool(Tool):
|
|
104 |
return "Invalid action."
|
105 |
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
110 |
inputs = {
|
111 |
-
"
|
112 |
-
"type": "string",
|
113 |
-
"description": "The action to perform (e.g., 'add', 'get', 'delete')."
|
114 |
-
},
|
115 |
-
"date": {
|
116 |
"type": "string",
|
117 |
-
"description": "The
|
118 |
-
},
|
119 |
-
"event": {
|
120 |
-
"type": "string",
|
121 |
-
"description": "The event description."
|
122 |
}
|
123 |
}
|
124 |
output_type = "string"
|
125 |
|
126 |
-
def
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
elif action == "get":
|
134 |
-
return f"Event on {date}: {self.events.get(date, 'No event found.')}"
|
135 |
-
elif action == "delete":
|
136 |
-
if date in self.events:
|
137 |
-
del self.events[date]
|
138 |
-
return f"Event on {date} deleted."
|
139 |
-
else:
|
140 |
-
return f"No event found on {date}."
|
141 |
-
else:
|
142 |
-
return "Invalid action."
|
143 |
-
|
144 |
class EmailTool(Tool):
|
145 |
name = "email"
|
146 |
description = "Sends and receives emails."
|
|
|
104 |
return "Invalid action."
|
105 |
|
106 |
|
107 |
+
|
108 |
+
class CalculatorTool(Tool):
|
109 |
+
name = "calculator"
|
110 |
+
description = "Performs mathematical calculations."
|
111 |
inputs = {
|
112 |
+
"expression": {
|
|
|
|
|
|
|
|
|
113 |
"type": "string",
|
114 |
+
"description": "The mathematical expression to evaluate."
|
|
|
|
|
|
|
|
|
115 |
}
|
116 |
}
|
117 |
output_type = "string"
|
118 |
|
119 |
+
def forward(self, expression: str):
|
120 |
+
try:
|
121 |
+
result = eval(expression)
|
122 |
+
return f"The result of the expression '{expression}' is {result}."
|
123 |
+
except Exception as e:
|
124 |
+
return f"Error evaluating expression: {str(e)}"
|
125 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
class EmailTool(Tool):
|
127 |
name = "email"
|
128 |
description = "Sends and receives emails."
|