cesarleoni commited on
Commit
6c718c0
·
verified ·
1 Parent(s): 475a39d

str obligatoriu

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -21,11 +21,10 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
21
  return "What magic will you build ?"
22
 
23
 
24
-
25
  @tool
26
- def calculus(arg1: str, arg2: float, arg3: float) -> Union[float, str]:
27
  """
28
- A tool that does basic math operations: addition, subtraction,
29
  multiplication, and division between two real numbers.
30
 
31
  Args:
@@ -34,20 +33,26 @@ def calculus(arg1: str, arg2: float, arg3: float) -> Union[float, str]:
34
  arg3: The second number
35
 
36
  Returns:
37
- The result of the math operation, or an error message if invalid input.
38
  """
39
- if arg1 == '+':
40
- return arg2 + arg3
41
- elif arg1 == '-':
42
- return arg2 - arg3
43
- elif arg1 == '*':
44
- return arg2 * arg3
45
- elif arg1 == '/':
46
- if arg3 == 0:
47
- return "Error: Division by zero!"
48
- return arg2 / arg3
49
-
50
- return "Error: Invalid operator. Use one of '+', '-', '*', '/'"
 
 
 
 
 
 
51
 
52
 
53
  @tool
 
21
  return "What magic will you build ?"
22
 
23
 
 
24
  @tool
25
+ def calculus(arg1: str, arg2: float, arg3: float) -> str:
26
  """
27
+ A tool that performs basic math operations: addition, subtraction,
28
  multiplication, and division between two real numbers.
29
 
30
  Args:
 
33
  arg3: The second number
34
 
35
  Returns:
36
+ A string representing the result of the operation or an error message.
37
  """
38
+ try:
39
+ if arg1 == '+':
40
+ result = arg2 + arg3
41
+ elif arg1 == '-':
42
+ result = arg2 - arg3
43
+ elif arg1 == '*':
44
+ result = arg2 * arg3
45
+ elif arg1 == '/':
46
+ if arg3 == 0:
47
+ return "Error: Division by zero"
48
+ result = arg2 / arg3
49
+ else:
50
+ return "Error: Invalid operator. Use one of '+', '-', '*', '/'"
51
+
52
+ return str(result)
53
+ except Exception as e:
54
+ return f"Error: {str(e)}"
55
+
56
 
57
 
58
  @tool