gokceKy commited on
Commit
8f3f9bb
·
verified ·
1 Parent(s): aa2a817

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -9,20 +9,24 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def calculator(arg1: int, arg2: int) -> int:
13
  """
14
- Performs addition of two numbers.
15
 
16
  Args:
17
- arg1 (int): The first operand.
18
- arg2 (int): The second operand.
19
 
20
  Returns:
21
- int: The sum of the two numbers.
22
- """
23
- return arg1 + arg2
24
-
25
 
 
 
 
 
 
 
 
 
26
 
27
  @tool
28
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def calculator(operation: str) -> str:
13
  """
14
+ A simple calculator that evaluates a basic arithmetic operation given as a string.
15
 
16
  Args:
17
+ operation (str): A mathematical expression (e.g., '5 + 3', '10 - 2', '4 * 7', '20 / 5').
 
18
 
19
  Returns:
20
+ str: The result of the calculation as a string.
 
 
 
21
 
22
+ Raises:
23
+ ValueError: If the operation is invalid or cannot be computed.
24
+ """
25
+ try:
26
+ result = eval(operation)
27
+ return str(result)
28
+ except Exception as e:
29
+ raise ValueError(f"Invalid operation: {operation}. Error: {str(e)}")
30
 
31
  @tool
32
  def get_current_time_in_timezone(timezone: str) -> str: