Sellid commited on
Commit
e06e5b0
·
verified ·
1 Parent(s): 01f20c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -3,6 +3,8 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
@@ -120,6 +122,33 @@ def get_random_joke() -> str:
120
  except Exception as e:
121
  return f"Error fetching joke: {str(e)}"
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  final_answer = FinalAnswerTool()
124
 
125
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
@@ -142,7 +171,7 @@ with open("prompts.yaml", 'r') as stream:
142
  agent = CodeAgent(
143
  model=model,
144
  tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search, get_open_meteo_weather,
145
- get_random_joke], ## add your tools here (don't remove final answer)
146
  max_steps=6,
147
  verbosity_level=1,
148
  grammar=None,
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import secrets
7
+ import string
8
  from tools.final_answer import FinalAnswerTool
9
 
10
  from Gradio_UI import GradioUI
 
122
  except Exception as e:
123
  return f"Error fetching joke: {str(e)}"
124
 
125
+ @tool
126
+ def generate_password(length: int = 16, use_punctuation: bool = True) -> str:
127
+ """
128
+ Generates a secure random password with at least 16 characters.
129
+
130
+ Args:
131
+ length: The desired length of the password (must be at least 16; default is 16).
132
+ use_punctuation: Whether to include punctuation symbols in the password (default is True).
133
+
134
+ Returns:
135
+ A randomly generated password as a string.
136
+
137
+ Raises:
138
+ ValueError: If the requested length is less than 16.
139
+ """
140
+ if length < 16:
141
+ raise ValueError("Password length must be at least 16 characters")
142
+
143
+ # Build the alphabet from which to choose characters.
144
+ alphabet = string.ascii_letters + string.digits
145
+ if use_punctuation:
146
+ alphabet += string.punctuation
147
+
148
+ # Generate a secure random password using secrets.choice.
149
+ password = ''.join(secrets.choice(alphabet) for _ in range(length))
150
+ return password
151
+
152
  final_answer = FinalAnswerTool()
153
 
154
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
171
  agent = CodeAgent(
172
  model=model,
173
  tools=[final_answer, get_current_time_in_timezone, image_generation_tool, search, get_open_meteo_weather,
174
+ get_random_joke, generate_password], ## add your tools here (don't remove final answer)
175
  max_steps=6,
176
  verbosity_level=1,
177
  grammar=None,