leghair commited on
Commit
c49cc5d
·
verified ·
1 Parent(s): e216d94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -29
app.py CHANGED
@@ -11,37 +11,26 @@ from Gradio_UI import GradioUI
11
 
12
 
13
  @tool
14
- def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
15
- """Converts an amount from one currency to another using real-time exchange rates.
16
-
17
  Args:
18
- amount (float): The amount to convert.
19
- from_currency (str): The 3-letter currency code to convert from (e.g., 'USD').
20
- to_currency (str): The 3-letter currency code to convert to (e.g., 'EUR').
21
-
22
- Returns:
23
- str: A formatted string with the converted amount and exchange rate.
24
  """
25
- try:
26
- # Fetch exchange rate data
27
- api_url = f"https://api.exchangerate-api.com/v4/latest/{from_currency.upper()}"
28
- response = requests.get(api_url)
29
- data = response.json()
30
-
31
- if "rates" not in data:
32
- return "Error: Could not retrieve exchange rates."
33
-
34
- # Convert the amount
35
- rate = data["rates"].get(to_currency.upper())
36
- if not rate:
37
- return f"Error: Unsupported currency '{to_currency}'."
38
-
39
- converted_amount = round(amount * rate, 2)
40
- return f"{amount} {from_currency.upper()} is approximately {converted_amount} {to_currency.upper()} (Rate: {rate})."
41
 
42
- except Exception as e:
43
- return f"Error fetching exchange rates: {str(e)}"
44
-
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str:
47
  """A tool that fetches the current local time in a specified timezone.
@@ -79,7 +68,7 @@ with open("prompts.yaml", 'r') as stream:
79
 
80
  agent = CodeAgent(
81
  model=model,
82
- tools=[final_answer, convert_currency], ## add your tools here (don't remove final answer)
83
  max_steps=6,
84
  verbosity_level=1,
85
  grammar=None,
 
11
 
12
 
13
  @tool
14
+ def generate_password(arg1: str, arg2: int) -> str:
15
+ """A tool that generates a random password based on the specified complexity.
16
+
17
  Args:
18
+ arg1: The complexity type ('simple' or 'complex').
19
+ arg2: The length of the password.
 
 
 
 
20
  """
21
+ if arg2 < 4:
22
+ return "Error: Password length must be at least 4 characters."
23
+
24
+ if arg1.lower() == "simple":
25
+ chars = string.ascii_letters + string.digits # Letters and numbers
26
+ elif arg1.lower() == "complex":
27
+ chars = string.ascii_letters + string.digits + string.punctuation # Includes symbols
28
+ else:
29
+ return "Error: Use 'simple' or 'complex' for the complexity type."
30
+
31
+ password = "".join(random.choice(chars) for _ in range(arg2))
32
+ return f"Generated {arg1.lower()} password: {password}"
 
 
 
 
33
 
 
 
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str:
36
  """A tool that fetches the current local time in a specified timezone.
 
68
 
69
  agent = CodeAgent(
70
  model=model,
71
+ tools=[final_answer, generate_password], ## add your tools here (don't remove final answer)
72
  max_steps=6,
73
  verbosity_level=1,
74
  grammar=None,