Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
final_answer = FinalAnswerTool()
|
| 39 |
|
|
@@ -56,7 +74,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer,my_custom_tool], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def convert_currency(from_currency: str, to_currency: str, amount: float) -> str:
|
| 39 |
+
"""
|
| 40 |
+
Converts an amount from one currency to another using real-time exchange rates.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
from_currency: The currency code to convert from (e.g., 'USD').
|
| 44 |
+
to_currency: The currency code to convert to (e.g., 'EUR').
|
| 45 |
+
amount: The amount of money to convert.
|
| 46 |
+
"""
|
| 47 |
+
try:
|
| 48 |
+
url = f"https://api.exchangerate.host/convert?from={from_currency}&to={to_currency}&amount={amount}"
|
| 49 |
+
response = requests.get(url)
|
| 50 |
+
data = response.json()
|
| 51 |
+
result = data["result"]
|
| 52 |
+
return f"{amount} {from_currency} = {result:.2f} {to_currency}"
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return f"Failed to convert currency: {str(e)}"
|
| 55 |
|
| 56 |
final_answer = FinalAnswerTool()
|
| 57 |
|
|
|
|
| 74 |
|
| 75 |
agent = CodeAgent(
|
| 76 |
model=model,
|
| 77 |
+
tools=[final_answer,my_custom_tool, convert_currency], ## add your tools here (don't remove final answer)
|
| 78 |
max_steps=6,
|
| 79 |
verbosity_level=1,
|
| 80 |
grammar=None,
|