HSinghHuggingFace commited on
Commit
0b57db4
·
1 Parent(s): 3d1237b

currency conversion tool

Browse files
Files changed (2) hide show
  1. app.py +16 -8
  2. requirements.txt +1 -0
app.py CHANGED
@@ -4,19 +4,27 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -51,7 +59,7 @@ with open("prompts.yaml", 'r') as stream:
51
 
52
  agent = CodeAgent(
53
  model=model,
54
- tools=[final_answer], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from forex_python.converter import CurrencyRates
8
+ from smolagents import tool
9
 
10
  from Gradio_UI import GradioUI
11
 
 
12
  @tool
13
+ def currency_converter(amount: int, from_currency: str, to_currency: str) -> float:
14
+ """A tool that converts an amount from one currency to another using real-time exchange rates.
 
15
  Args:
16
+ amount: The amount of money to convert (integer value).
17
+ from_currency: The currency code of the original currency (e.g., 'USD').
18
+ to_currency: The currency code of the target currency (e.g., 'INR').
19
+ Returns:
20
+ Converted amount as per the current exchange rate.
21
  """
22
+ try:
23
+ c = CurrencyRates()
24
+ converted_amount = c.convert(from_currency, to_currency, amount)
25
+ return converted_amount
26
+ except Exception as e:
27
+ return f"Error in currency conversion: {str(e)}"
28
 
29
  @tool
30
  def get_current_time_in_timezone(timezone: str) -> str:
 
59
 
60
  agent = CodeAgent(
61
  model=model,
62
+ tools=[currency_converter,get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
63
  max_steps=6,
64
  verbosity_level=1,
65
  grammar=None,
requirements.txt CHANGED
@@ -3,3 +3,4 @@ smolagents
3
  requests
4
  duckduckgo_search
5
  pandas
 
 
3
  requests
4
  duckduckgo_search
5
  pandas
6
+ forex-python