Spaces:
Sleeping
Sleeping
basic calculator
Browse filessupport +, -, *, /
app.py
CHANGED
|
@@ -7,20 +7,37 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
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
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
try:
|
| 20 |
-
answer =
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
-
return f"Error computing '{
|
| 24 |
|
| 25 |
@tool
|
| 26 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -59,7 +76,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 59 |
|
| 60 |
agent = CodeAgent(
|
| 61 |
model=model,
|
| 62 |
-
tools=[final_answer, get_current_time_in_timezone,
|
| 63 |
max_steps=6,
|
| 64 |
verbosity_level=1,
|
| 65 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
+
def basic_calculator(num1:float, num2:float, act:str)-> float: #it's import to specify the return type
|
| 12 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 13 |
+
"""A tool that takes two numbers and the action to perform on them.
|
| 14 |
+
The tool is capable of four actions: add, substract, multiply, divide
|
| 15 |
Args:
|
| 16 |
+
num1: the first number
|
| 17 |
+
num2: the second number
|
| 18 |
+
act: what action to take
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
+
answer = 0
|
| 22 |
+
action = ''
|
| 23 |
+
if act == '+' || act == 'add' || act == 'append' || act == 'plus':
|
| 24 |
+
answer = num1 + num2
|
| 25 |
+
action = '+'
|
| 26 |
+
elif act == '-' || act == 'minus' || act = 'substract':
|
| 27 |
+
answer = num1 - num2
|
| 28 |
+
action = '-'
|
| 29 |
+
elif act == '*' || act == 'mul' || act == 'multiply':
|
| 30 |
+
answer = num1 * num2
|
| 31 |
+
action = '*'
|
| 32 |
+
elif act == '/' || act == 'div' || act == 'divide':
|
| 33 |
+
answer = num1 / num2
|
| 34 |
+
action = '/'
|
| 35 |
+
else:
|
| 36 |
+
return f"unsupported action type: {action}"
|
| 37 |
+
|
| 38 |
+
return f"{num1} {action} {num2} = {answer}"
|
| 39 |
except Exception as e:
|
| 40 |
+
return f"Error computing '{num1}' and '{num2}' with '{act}'"
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
+
tools=[final_answer, get_current_time_in_timezone, basic_calculator], ## add your tools here (don't remove final answer)
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|