Spaces:
Sleeping
Sleeping
First basic tool : Calculator
Browse files
app.py
CHANGED
|
@@ -18,6 +18,37 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def tool_calculator(num1: int, num2: int, operation: str) -> int:
|
| 23 |
+
|
| 24 |
+
"""
|
| 25 |
+
A tool that performs an airthmetic operation on the input two numbers. takes two numbers and an operation as inputs.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
num1: The first number
|
| 29 |
+
num2: The second number
|
| 30 |
+
operation: The mathematical operation (e.g., 'add', 'subtract', 'multiply', 'divide')
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
# Validate that inputs are numbers
|
| 34 |
+
if not isinstance(num1, (int, float)) or not isinstance(num2, (int, float)):
|
| 35 |
+
return "Error: Inputs must be numbers."
|
| 36 |
+
|
| 37 |
+
# Perform the requested operation
|
| 38 |
+
if operation == "add":
|
| 39 |
+
return num1 + num2
|
| 40 |
+
elif operation == "subtract":
|
| 41 |
+
return num1 - num2
|
| 42 |
+
elif operation == "multiply":
|
| 43 |
+
return num1 * num2
|
| 44 |
+
elif operation == "divide":
|
| 45 |
+
# Check for division by zero
|
| 46 |
+
if num2 == 0:
|
| 47 |
+
return "Error: Division by zero is not allowed."
|
| 48 |
+
return num1 / num2
|
| 49 |
+
else:
|
| 50 |
+
return "Error: Invalid operation. Choose from 'add', 'subtract', 'multiply', 'divide'."
|
| 51 |
+
|
| 52 |
@tool
|
| 53 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 54 |
"""A tool that fetches the current local time in a specified timezone.
|