Spaces:
Sleeping
Sleeping
added current currency rate converter tool
Browse files
app.py
CHANGED
@@ -18,6 +18,22 @@ 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.
|
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
+
@tool
|
22 |
+
def get_current_exchange_rate_in_USD(currency: str, amount: float) -> str:
|
23 |
+
"""A tool that fetches the current exchange rate for specified currency against the US Dollar (USD)
|
24 |
+
Args:
|
25 |
+
currency: A string representing a valid currency (e.g., 'CAD' for Canadian Dollar).
|
26 |
+
amount: A float representing an amount of currency to convert to USD.
|
27 |
+
"""
|
28 |
+
data_url = 'https://open.er-api.com/v6/latest/USD'
|
29 |
+
try:
|
30 |
+
r = requests.get(data_url)
|
31 |
+
rates = r.json()['rates']
|
32 |
+
rate = rates[currency.upper()]
|
33 |
+
return f"{amount} units of {currency.upper()} currency is worth ${float(rate)*amount} US dollars."
|
34 |
+
except Exception as e:
|
35 |
+
return f"Error fetching currency rate for '{currency}': {str(e)}"
|
36 |
+
|
37 |
@tool
|
38 |
def get_current_time_in_timezone(timezone: str) -> str:
|
39 |
"""A tool that fetches the current local time in a specified timezone.
|