Spaces:
Sleeping
Sleeping
added currency_converter tool to agent
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -27,6 +28,32 @@ def web_search(prompt: str) -> str:
|
|
| 27 |
search_tool = DuckDuckGoSearchTool(max_results=5)
|
| 28 |
return search_tool(prompt)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
@tool
|
| 31 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 32 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -65,7 +92,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 65 |
|
| 66 |
agent = CodeAgent(
|
| 67 |
model=model,
|
| 68 |
-
tools=[final_answer, get_current_time_in_timezone, web_search, image_generation_tool], ## add your tools here (don't remove final answer)
|
| 69 |
max_steps=6,
|
| 70 |
verbosity_level=1,
|
| 71 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from forex_python.converter import CurrencyRates
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 28 |
search_tool = DuckDuckGoSearchTool(max_results=5)
|
| 29 |
return search_tool(prompt)
|
| 30 |
|
| 31 |
+
@tool
|
| 32 |
+
def convert_currency(amount:float, from_currency:str, to_currency:str) -> float:
|
| 33 |
+
""" A tool that converts a specified amount from one currency to another.
|
| 34 |
+
Args:
|
| 35 |
+
amount: The amount of money to convert (e.g. 10.5).
|
| 36 |
+
from_currency: The currency code of the source currency (e.g., 'USD').
|
| 37 |
+
to_currency: The currency code of the target currency (e.g., 'EUR').
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
# Initialize the CurrencyRates object
|
| 41 |
+
c = CurrencyRates()
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
# Fetch the conversion rate
|
| 45 |
+
rate = c.get_rate(from_currency.upper(), to_currency.upper())
|
| 46 |
+
# Perform the conversion
|
| 47 |
+
converted_amount = amount * rate
|
| 48 |
+
return converted_amount
|
| 49 |
+
|
| 50 |
+
except RatesNotAvailableError:
|
| 51 |
+
return f"Error: Conversionrate not available for {from_currency} to {to_currency}."
|
| 52 |
+
except ValueError:
|
| 53 |
+
return f"Error: Invalid amount entered."
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return f"An unexpected error occurred: {e}"
|
| 56 |
+
|
| 57 |
@tool
|
| 58 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 59 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 92 |
|
| 93 |
agent = CodeAgent(
|
| 94 |
model=model,
|
| 95 |
+
tools=[final_answer, get_current_time_in_timezone, web_search, convert_currency, image_generation_tool], ## add your tools here (don't remove final answer)
|
| 96 |
max_steps=6,
|
| 97 |
verbosity_level=1,
|
| 98 |
grammar=None,
|