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

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +32 -11
tools.py CHANGED
@@ -65,23 +65,44 @@ class HubStatsTool(Tool):
65
  except Exception as e:
66
  return f"Error fetching models for {author}: {str(e)}"
67
 
68
- class CalculatorTool(Tool):
69
- name = "calculator"
70
- description = "Performs mathematical calculations."
71
  inputs = {
72
- "expression": {
 
 
 
 
73
  "type": "string",
74
- "description": "The mathematical expression to evaluate."
 
 
 
 
 
75
  }
76
  }
77
  output_type = "string"
78
 
79
- def forward(self, expression: str):
80
- try:
81
- result = eval(expression)
82
- return f"The result of the expression '{expression}' is {result}."
83
- except Exception as e:
84
- return f"Error evaluating expression: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  class CalendarTool(Tool):
87
  name = "calendar"
 
65
  except Exception as e:
66
  return f"Error fetching models for {author}: {str(e)}"
67
 
68
+ class CalendarTool(Tool):
69
+ name = "calendar"
70
+ description = "Manages and retrieves information about dates and events."
71
  inputs = {
72
+ "action": {
73
+ "type": "string",
74
+ "description": "The action to perform (e.g., 'add', 'get', 'delete')."
75
+ },
76
+ "date": {
77
  "type": "string",
78
+ "description": "The date of the event (format: YYYY-MM-DD)."
79
+ },
80
+ "event": {
81
+ "type": "string",
82
+ "description": "The event description.",
83
+ "nullable": True # Add this line to specify that 'event' is nullable
84
  }
85
  }
86
  output_type = "string"
87
 
88
+ def __init__(self):
89
+ self.events = {}
90
+
91
+ def forward(self, action: str, date: str, event: str = None):
92
+ if action == "add":
93
+ self.events[date] = event
94
+ return f"Event '{event}' added to {date}."
95
+ elif action == "get":
96
+ return f"Event on {date}: {self.events.get(date, 'No event found.')}"
97
+ elif action == "delete":
98
+ if date in self.events:
99
+ del self.events[date]
100
+ return f"Event on {date} deleted."
101
+ else:
102
+ return f"No event found on {date}."
103
+ else:
104
+ return "Invalid action."
105
+
106
 
107
  class CalendarTool(Tool):
108
  name = "calendar"