trippyrocks commited on
Commit
9de8f22
·
verified ·
1 Parent(s): f318b15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -19,25 +19,25 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
19
  return "What magic will you build ?"
20
 
21
  @tool
22
- def time_converter(time_str: str) -> str:
23
- """A tool that converts a time string from 12-hour format (with AM/PM) to 24-hour format.
 
24
 
25
  Args:
26
- time_str: A time string in 12-hour format (e.g., "02:30 PM").
 
27
 
28
  Returns:
29
- str: The time in 24-hour format (e.g., "14:30") or an error message.
30
  """
31
- from datetime import datetime
32
  try:
33
- dt = datetime.strptime(time_str, "%I:%M %p")
34
- result = dt.strftime("%H:%M")
35
- print(f"Converted time: {result}") # For debugging/logging
36
- return result
 
37
  except Exception as e:
38
- error_msg = f"Error converting time: {str(e)}"
39
- print(error_msg) # For debugging/logging
40
- return error_msg
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str:
 
19
  return "What magic will you build ?"
20
 
21
  @tool
22
+ @tool
23
+ def calculator(operation: str) -> str:
24
+ """A simple calculator tool that safely evaluates basic math expressions.
25
 
26
  Args:
27
+ operation: The mathematical expression to evaluate (e.g., "2 + 2", "5 * 3").
28
+ Supports basic operations (+, -, *, /) and parentheses.
29
 
30
  Returns:
31
+ str: The result of the calculation or an error message.
32
  """
 
33
  try:
34
+ allowed_chars = set("0123456789+-*/ .()")
35
+ if not all(c in allowed_chars for c in operation):
36
+ return "Error: Only basic math operations allowed"
37
+ result = eval(operation, {"__builtins__": {}})
38
+ return f"Result: {result}"
39
  except Exception as e:
40
+ return f"Error calculating {operation}: {str(e)}"
 
 
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str: