Spaces:
Sleeping
Sleeping
mriusero
commited on
Commit
·
8d1eb96
1
Parent(s):
7049c20
feat: add calculator
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
2 |
import os
|
3 |
import datetime
|
4 |
import requests
|
|
|
5 |
import pytz
|
6 |
import yaml
|
7 |
from tools.final_answer import FinalAnswerTool
|
@@ -21,6 +22,28 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
21 |
"""
|
22 |
return "What magic will you build ?"
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
@tool
|
25 |
def get_current_time_in_timezone(timezone: str) -> str:
|
26 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -61,7 +84,13 @@ with open("prompts.yaml", 'r') as stream:
|
|
61 |
|
62 |
agent = CodeAgent(
|
63 |
model=model,
|
64 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
max_steps=6,
|
66 |
verbosity_level=1,
|
67 |
grammar=None,
|
|
|
2 |
import os
|
3 |
import datetime
|
4 |
import requests
|
5 |
+
import urllib.parse
|
6 |
import pytz
|
7 |
import yaml
|
8 |
from tools.final_answer import FinalAnswerTool
|
|
|
22 |
"""
|
23 |
return "What magic will you build ?"
|
24 |
|
25 |
+
@tool
|
26 |
+
def calculator(operation: str, expression: str) -> str:
|
27 |
+
"""
|
28 |
+
A tool that performs advanced mathematical operations using the Newton API.
|
29 |
+
Args:
|
30 |
+
operation: The mathematical operation to perform (e.g., 'derive', 'integrate').
|
31 |
+
expression: The mathematical expression to operate on.
|
32 |
+
Returns:
|
33 |
+
The result of the mathematical operation as a string.
|
34 |
+
"""
|
35 |
+
encoded_expression = urllib.parse.quote(expression)
|
36 |
+
url = f"https://newton.now.sh/api/v2/{operation}/{encoded_expression}"
|
37 |
+
|
38 |
+
response = requests.get(url)
|
39 |
+
|
40 |
+
if response.status_code == 200:
|
41 |
+
result = response.json().get("result")
|
42 |
+
return result
|
43 |
+
else:
|
44 |
+
return f"Error: Unable to fetch result. Status code: {response.status_code}"
|
45 |
+
|
46 |
+
|
47 |
@tool
|
48 |
def get_current_time_in_timezone(timezone: str) -> str:
|
49 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
84 |
|
85 |
agent = CodeAgent(
|
86 |
model=model,
|
87 |
+
tools=[
|
88 |
+
final_answer,
|
89 |
+
web_search,
|
90 |
+
visit_webpage,
|
91 |
+
get_current_time_in_timezone,
|
92 |
+
calculator,
|
93 |
+
], ## add your tools here (don't remove final answer)
|
94 |
max_steps=6,
|
95 |
verbosity_level=1,
|
96 |
grammar=None,
|