File size: 2,143 Bytes
9825718
 
c73f2f1
9825718
 
 
 
3761a98
 
9825718
 
 
 
 
c73f2f1
9825718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c73f2f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)"