helloparthshah commited on
Commit
f5ed8c8
·
1 Parent(s): 576227b

Removing unused file

Browse files
Files changed (1) hide show
  1. CEO/tool_loader.py +0 -114
CEO/tool_loader.py DELETED
@@ -1,114 +0,0 @@
1
- import importlib
2
- import importlib.util
3
- import os
4
- import types
5
- import pip
6
- from google.genai import types
7
- import sys
8
-
9
- from CEO.utils.suppress_outputs import suppress_output
10
-
11
- toolsImported = []
12
-
13
- TOOLS_DIRECTORY = os.path.abspath("./tools")
14
-
15
- class Tool:
16
- def __init__(self, toolClass):
17
- suppress_output(self.load_tool)(toolClass)
18
-
19
- def load_tool(self, toolClass):
20
- self.tool = toolClass()
21
- self.inputSchema = self.tool.inputSchema
22
- self.name = self.inputSchema["name"]
23
- self.description = self.inputSchema["description"]
24
- self.dependencies = self.tool.dependencies
25
- for package in self.tool.dependencies:
26
- try:
27
- __import__(package.split('==')[0])
28
- except ImportError:
29
- print(f"Installing {package}")
30
- if '==' in package:
31
- package = package.split('==')[0]
32
- pip.main(['install', package])
33
-
34
- def run(self, query):
35
- return self.tool.run(**query)
36
-
37
- class ToolLoader:
38
- def __init__(self):
39
- self.toolsImported = []
40
- self.load_tools()
41
- pass
42
-
43
- def load_tools(self):
44
- self.toolsImported = []
45
- for filename in os.listdir(TOOLS_DIRECTORY):
46
- if filename.endswith(".py") and filename != "__init__.py":
47
- module_name = filename[:-3]
48
- spec = importlib.util.spec_from_file_location(module_name, f"{TOOLS_DIRECTORY}/{filename}")
49
- foo = importlib.util.module_from_spec(spec)
50
- spec.loader.exec_module(foo)
51
- class_name = foo.__all__[0]
52
- toolClass = getattr(foo, class_name)
53
- toolObj = Tool(toolClass)
54
- self.toolsImported.append(toolObj)
55
-
56
- def runTool(self, toolName, query):
57
- for tool in self.toolsImported:
58
- if tool.name == toolName:
59
- return tool.run(query)
60
- return {
61
- "status": "error",
62
- "message": f"Tool {toolName} not found",
63
- "output": None
64
- }
65
-
66
- def getTools(self):
67
- toolsList = []
68
- for tool in self.toolsImported:
69
- parameters = types.Schema()
70
- parameters.type = tool.inputSchema["parameters"]["type"]
71
- properties = {}
72
- for prop, value in tool.inputSchema["parameters"]["properties"].items():
73
- properties[prop] = types.Schema(
74
- type=value["type"],
75
- description=value["description"]
76
- )
77
- parameters.properties = properties
78
- parameters.required = tool.inputSchema["parameters"].get("required", [])
79
- function = types.FunctionDeclaration(
80
- name=tool.inputSchema["name"],
81
- description=tool.inputSchema["description"],
82
- parameters=parameters,
83
- )
84
- toolType = types.Tool(function_declarations=[function])
85
- toolsList.append(toolType)
86
- # toolsList.append({
87
- # "type": "function",
88
- # "function": tool.inputSchema
89
- # })
90
- return toolsList
91
-
92
- def delete_tool(self, toolName, toolFile):
93
- try:
94
- os.remove(toolFile)
95
- for tool in self.toolsImported:
96
- if tool.name == toolName:
97
- self.toolsImported.remove(tool)
98
- return {
99
- "status": "success",
100
- "message": f"Tool {toolName} deleted",
101
- "output": None
102
- }
103
- except Exception as e:
104
- return {
105
- "status": "error",
106
- "message": f"Tool {toolName} not found",
107
- "output": None
108
- }
109
-
110
- toolLoader = ToolLoader()
111
-
112
- # Example usage
113
- # print(toolLoader.getTools())
114
- # print(toolLoader.runTool("AgentCreator", {"agent_name": "Kunla","base_model":"llama3.2","system_prompt": "You love making the indian dish called Kulcha. You declare that in every conversation you have in a witty way." }))