from smolagents import DuckDuckGoSearchTool from smolagents import Tool import random # Initialize the DuckDuckGo search tool search_tool = DuckDuckGoSearchTool() class CurrencyConverterTool(Tool): name = "currency_converter" description = "Converts amounts between different currencies using dummy exchange rates." inputs = { "amount": { "type": "number", # Cambiado de "float" a "number" "description": "The amount to convert." }, "from_currency": { "type": "string", "description": "The source currency code (e.g., USD, EUR, CLP)." }, "to_currency": { "type": "string", "description": "The target currency code (e.g., USD, EUR, CLP)." } } output_type = "string" def forward(self, amount: float, from_currency: str, to_currency: str): # Dummy exchange rates (base: USD) exchange_rates = { "USD": 1.0, "EUR": 0.85, "CLP": 800.0, "ARS": 350.0, "BRL": 5.2, "MXN": 18.5, "GBP": 0.75, "JPY": 110.0, "CAD": 1.25 } # Validate currencies if from_currency not in exchange_rates or to_currency not in exchange_rates: available_currencies = ", ".join(exchange_rates.keys()) return f"Error: Moneda no soportada. Divisas disponibles: {available_currencies}" # Same currency conversion if from_currency == to_currency: return f"{amount:.2f} {from_currency} = {amount:.2f} {to_currency} (misma divisa)" # Convert to USD first, then to target currency usd_amount = amount / exchange_rates[from_currency] converted_amount = usd_amount * exchange_rates[to_currency] # Add small random variation to simulate real market fluctuations (±2%) variation = random.uniform(-0.02, 0.02) converted_amount *= (1 + variation) return f"{amount:.2f} {from_currency} = {converted_amount:.2f} {to_currency} (tasa simulada)"