Spaces:
Sleeping
Sleeping
Update app.py
Browse filesPrime checker tool
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
@@ -9,14 +10,25 @@ 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 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +67,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer,
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
+
import math
|
| 4 |
import requests
|
| 5 |
import pytz
|
| 6 |
import yaml
|
|
|
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
+
def check_prime(n:int)-> str: #it's import to specify the return type
|
| 14 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 15 |
+
"""A tool that checks whether a given integer is prime or not.
|
| 16 |
Args:
|
| 17 |
+
n: the given integer
|
|
|
|
| 18 |
"""
|
| 19 |
+
output = "The given integer is"
|
| 20 |
+
if n < 2:
|
| 21 |
+
return f"{output} False."
|
| 22 |
+
if n in (2, 3):
|
| 23 |
+
return f"{output} False."
|
| 24 |
+
if n % 2 == 0 or n % 3 == 0:
|
| 25 |
+
return f"{output} False."
|
| 26 |
+
|
| 27 |
+
limit = int(math.sqrt(n))
|
| 28 |
+
for i in range(5, limit + 1, 6):
|
| 29 |
+
if n % i == 0 or n % (i + 2) == 0:
|
| 30 |
+
return f"{output} False."
|
| 31 |
+
return f"{output} True."
|
| 32 |
|
| 33 |
@tool
|
| 34 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 67 |
|
| 68 |
agent = CodeAgent(
|
| 69 |
model=model,
|
| 70 |
+
tools=[final_answer, check_prime], ## add your tools here (don't remove final answer)
|
| 71 |
max_steps=6,
|
| 72 |
verbosity_level=1,
|
| 73 |
grammar=None,
|