PolPC13 commited on
Commit
14fdbf2
·
1 Parent(s): 8d74186

Modified currency_coverted formula

Browse files
Files changed (1) hide show
  1. tools/exchange_rates.py +8 -4
tools/exchange_rates.py CHANGED
@@ -13,13 +13,17 @@ class ExchangeRatesTool(Tool):
13
  inputs = {'amount': {'type': 'number', 'description': 'The amount to convert.'},
14
  'from_currency': {'type': 'string', 'description': 'The currency to convert from.'},
15
  'to_currency': {'type': 'string', 'description': 'The currency to convert to.'}}
16
- output_type = "string"
17
 
18
  def forward(self, amount: float, from_currency: str, to_currency: str) -> float:
19
- return currency_converter(amount, from_currency, to_currency)
 
 
 
 
20
 
21
 
22
- def currency_converter(amount: float, from_currency: str, to_currency: str) -> str:
23
  """Convierte un monto dado de una divisa a otra usando tipos de cambio en tiempo real.
24
 
25
  Args:
@@ -66,7 +70,7 @@ def currency_converter(amount: float, from_currency: str, to_currency: str) -> s
66
  # Convert amount in USD to 'to_currency'
67
  converted_amount = amount_in_usd * to_usd_rate
68
 
69
- return f"{amount:.2f} {from_currency_upper} es igual a {converted_amount:.2f} {to_currency_upper}."
70
 
71
  except requests.exceptions.HTTPError as e:
72
  return f"Error HTTP al obtener tasas: {e}"
 
13
  inputs = {'amount': {'type': 'number', 'description': 'The amount to convert.'},
14
  'from_currency': {'type': 'string', 'description': 'The currency to convert from.'},
15
  'to_currency': {'type': 'string', 'description': 'The currency to convert to.'}}
16
+ output_type = "number"
17
 
18
  def forward(self, amount: float, from_currency: str, to_currency: str) -> float:
19
+ result = currency_converter(amount, from_currency, to_currency)
20
+ if isinstance(result, float):
21
+ return result
22
+ else:
23
+ raise Exception(result)
24
 
25
 
26
+ def currency_converter(amount: float, from_currency: str, to_currency: str) -> float | str:
27
  """Convierte un monto dado de una divisa a otra usando tipos de cambio en tiempo real.
28
 
29
  Args:
 
70
  # Convert amount in USD to 'to_currency'
71
  converted_amount = amount_in_usd * to_usd_rate
72
 
73
+ return converted_amount
74
 
75
  except requests.exceptions.HTTPError as e:
76
  return f"Error HTTP al obtener tasas: {e}"