File size: 2,694 Bytes
686a009
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from typing import List
from langchain.tools import tool
from logger.decorators import log_entry
from utils.expense_calculator import Calculator

class CalculatorTool:
    """
    A wrapper class for trip-related financial calculations using a custom Calculator utility.

    This class exposes several LangChain-compatible tools for estimating hotel costs,
    calculating total expenses, and determining daily budgets.
    """

    def __init__(self):
        """
        Initialize the CalculatorTool by creating an instance of Calculator and setting up tools.
        """
        self.calculator = Calculator()
        self.calculator_tool_list = self._setup_tools()

    def _setup_tools(self) -> List:
        """
        Define and register calculator tools related to trip planning.

        Returns:
            List: A list of LangChain tool functions for financial calculations.
        """

        @tool
        @log_entry
        def estimate_total_hotel_cost(price_per_night: str, total_days: float) -> float:
            """
            Estimate the total hotel cost for a trip.

            Args:
                price_per_night (str): Cost per night for the hotel stay (may include currency symbol).
                total_days (float): Number of nights staying at the hotel.

            Returns:
                float: Total cost for the hotel stay.
            """
            print('Entered into estimate_total_hotel_cost().')
            return self.calculator.multiply(price_per_night, total_days)

        @tool
        @log_entry
        def calculate_total_expense(*costs: float) -> float:
            """
            Calculate the total trip expense by summing up individual cost items.

            Args:
                *costs (float): A variable number of expense values (e.g., hotel, food, transport).

            Returns:
                float: The total combined expense.
            """
            print('Entered into calculate_total_expense().')
            return self.calculator.calculate_total(*costs)

        @tool
        @log_entry
        def calculate_daily_expense_budget(total_cost: float, days: int) -> float:
            """
            Calculate the average daily budget for the trip.

            Args:
                total_cost (float): Total trip cost.
                days (int): Number of days in the trip.

            Returns:
                float: Estimated daily budget.
            """
            print('Entered into calculate_daily_expense_budget().')
            return self.calculator.calculate_daily_budget(total_cost, days)

        return [estimate_total_hotel_cost, calculate_total_expense, calculate_daily_expense_budget]