Spaces:
Sleeping
Sleeping
str obligatoriu
Browse files
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) ->
|
| 27 |
"""
|
| 28 |
-
A tool that
|
| 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 |
-
|
| 38 |
"""
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|