jarguello76 commited on
Commit
e0a2b8d
·
verified ·
1 Parent(s): 02ed79f

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +13 -31
tools.py CHANGED
@@ -104,43 +104,25 @@ class CalendarTool(Tool):
104
  return "Invalid action."
105
 
106
 
107
- class CalendarTool(Tool):
108
- name = "calendar"
109
- description = "Manages and retrieves information about dates and events."
 
110
  inputs = {
111
- "action": {
112
- "type": "string",
113
- "description": "The action to perform (e.g., 'add', 'get', 'delete')."
114
- },
115
- "date": {
116
  "type": "string",
117
- "description": "The date of the event (format: YYYY-MM-DD)."
118
- },
119
- "event": {
120
- "type": "string",
121
- "description": "The event description."
122
  }
123
  }
124
  output_type = "string"
125
 
126
- def __init__(self):
127
- self.events = {}
128
-
129
- def forward(self, action: str, date: str, event: str = None):
130
- if action == "add":
131
- self.events[date] = event
132
- return f"Event '{event}' added to {date}."
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."