File size: 1,682 Bytes
8b2fc7e
 
 
 
 
8cf77a3
8b2fc7e
 
 
 
 
 
 
 
 
 
 
21611df
8b2fc7e
21611df
8b2fc7e
 
2ea8556
8b2fc7e
 
fde43e7
 
 
 
 
 
 
 
 
8b2fc7e
 
 
 
21611df
8b2fc7e
 
 
fde43e7
8b2fc7e
 
 
 
 
 
 
 
 
 
 
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

__all__ = ['ToolCreator']


class ToolCreator():
    dependencies = []

    inputSchema = {
        "name": "ToolCreator",
        "description": "Creates a tool for the given function",
        "parameters": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "The name of the tool to create",
                },
                "tool_code": {
                    "type": "string",
                    "description": "The code of the tool to create",
                },
            },
            "required": ["name", "tool_code"],
        }
    }
    
    def validate_tool_code(self, tool_code):
        # Basic validation to check if the code is a valid Python function
        try:
            compile(tool_code, '<string>', 'exec')
            return True, None
        except SyntaxError as e:
            print(f"Syntax error in tool code: {e}")
            return False, e

    def run(self, **kwargs):
        print("Running Tool Creator")
        name = kwargs.get("name")
        content = kwargs.get("tool_code")
        print(f"Tool Name: {name}")
        print(f"Tool Content: {content}")
        # Create the tool file
        tool_file_path = f"src/tools/user_tools/{name}.py"
        with open(tool_file_path, "w") as tool_file:
            tool_file.write(content)
        print(f"Tool file created at {tool_file_path}")
        return {
            "status": "success",
            "message": "Tool created successfully",
            "output": {
                "tool_file_path": tool_file_path,
                "tool_name": name,
            }
        }