File size: 1,469 Bytes
273c375
 
 
 
 
 
 
 
 
 
 
 
 
 
873e601
 
 
b8b0b89
 
873e601
 
273c375
 
 
873e601
273c375
 
 
 
 
 
 
 
 
873e601
 
 
273c375
 
 
 
 
 
 
 
 
873e601
 
 
 
 
 
 
 
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
"""
Module: tool_loader

This module defines the ToolLoader class for loading tools.

Dependencies:
- logging: Standard Python logging library for logging messages.
- transformers: Library for natural language processing with pre-trained models.
- utils.logger: Module providing logging functionalities.
- utils.tool_config: Module providing tool_names for configuration.

Classes:
- ToolLoader: A class for loading tools.
"""

import logging
from transformers import load_tool
from utils.logger import log_response  # Import the logger
from utils.tool_config import tool_names   

class ToolLoader:
    """
    A class for loading tools.
    """
    def __init__(self, tool_names):
        """
        Initializes an instance of the ToolLoader class.

        Args:
        - tool_names (list): A list of tool names to load.

        Returns:
        - None
        """
        self.tools = self.load_tools(tool_names)

    def load_tools(self, tool_names):
        """
        Loads tools based on the provided tool names.

        Args:
        - tool_names (list): A list of tool names to load.

        Returns:
        - list: A list of loaded tools.
        """
        loaded_tools = []
        for tool_name in tool_names:
            try:
                tool = load_tool(tool_name)
                loaded_tools.append(tool)
            except Exception as e:
                log_response(f"Error loading tool '{tool_name}': {e}")
        return loaded_tools