Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded password gen tooling
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
|
|
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
@@ -18,6 +20,32 @@ 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.
|
|
@@ -55,7 +83,9 @@ 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 requests
|
| 4 |
+
import random
|
| 5 |
+
import string
|
| 6 |
import pytz
|
| 7 |
import yaml
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 20 |
"""
|
| 21 |
return "What magic will you build ?"
|
| 22 |
|
| 23 |
+
# my test tool
|
| 24 |
+
@tool
|
| 25 |
+
def generate_password(length: int = 12, include_special: bool = True) -> str:
|
| 26 |
+
"""A tool that generates a random password of specified length.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
length: The length of the password (default: 12)
|
| 30 |
+
include_special: Whether to include special characters (default: True)
|
| 31 |
+
"""
|
| 32 |
+
# Define character sets
|
| 33 |
+
lowercase = string.ascii_lowercase
|
| 34 |
+
uppercase = string.ascii_uppercase
|
| 35 |
+
digits = string.digits
|
| 36 |
+
special = string.punctuation if include_special else ""
|
| 37 |
+
|
| 38 |
+
# Create character pool
|
| 39 |
+
all_chars = lowercase + uppercase + digits + special
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
# Generate password
|
| 43 |
+
password = ''.join(random.choice(all_chars) for _ in range(length))
|
| 44 |
+
|
| 45 |
+
return f"Here is a randomly generated password of length {length}: {password}"
|
| 46 |
+
except Exception as e:
|
| 47 |
+
return f"Error generating password of length {length} and special characters {include_special}"
|
| 48 |
+
|
| 49 |
@tool
|
| 50 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 51 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
+
tools=[final_answer,
|
| 87 |
+
get_current_time_in_timezone,
|
| 88 |
+
generate_password], ## add your tools here (don't remove final answer)
|
| 89 |
max_steps=6,
|
| 90 |
verbosity_level=1,
|
| 91 |
grammar=None,
|