helloparthshah commited on
Commit
30d98fa
·
1 Parent(s): bd20f16

Updating tools and QOL changes

Browse files
CEO/CEO.py CHANGED
@@ -17,18 +17,27 @@ class GeminiManager:
17
  self.system_prompt = f.read()
18
 
19
  def request(self, messages):
20
- response = self.client.models.generate_content(
21
- #model='gemini-2.5-pro-preview-03-25',
22
- model=self.model_name,
23
- #model='gemini-2.5-pro-exp-03-25',
24
- #model='gemini-2.0-flash',
25
- contents=messages,
26
- config=types.GenerateContentConfig(
27
- system_instruction=self.system_prompt,
28
- temperature=0.2,
29
- tools=self.toolsLoader.getTools(),
30
- ),
31
- )
 
 
 
 
 
 
 
 
 
32
 
33
  print(f"Response: {response}")
34
 
@@ -65,7 +74,12 @@ class GeminiManager:
65
  parts=parts
66
  )
67
  messages.append(function_response_content)
68
- self.request(messages)
 
 
 
 
 
69
  else:
70
  print("No tool calls found in the response.")
71
  return messages
 
17
  self.system_prompt = f.read()
18
 
19
  def request(self, messages):
20
+ try:
21
+ response = self.client.models.generate_content(
22
+ #model='gemini-2.5-pro-preview-03-25',
23
+ model=self.model_name,
24
+ #model='gemini-2.5-pro-exp-03-25',
25
+ #model='gemini-2.0-flash',
26
+ contents=messages,
27
+ config=types.GenerateContentConfig(
28
+ system_instruction=self.system_prompt,
29
+ temperature=0.2,
30
+ tools=self.toolsLoader.getTools(),
31
+ ),
32
+ )
33
+ except Exception as e:
34
+ print(f"Error: {e}")
35
+ shouldRetry = input("An error occurred. Do you want to retry? (y/n): ")
36
+ if shouldRetry.lower() == "y":
37
+ return self.request(messages)
38
+ else:
39
+ print("Ending the conversation.")
40
+ return messages
41
 
42
  print(f"Response: {response}")
43
 
 
74
  parts=parts
75
  )
76
  messages.append(function_response_content)
77
+ shouldContinue = input("Should I continue? (y/n): ")
78
+ if shouldContinue.lower() == "y":
79
+ return self.request(messages)
80
+ else:
81
+ print("Ending the conversation.")
82
+ return messages
83
  else:
84
  print("No tool calls found in the response.")
85
  return messages
CEO/tool_loader.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import types
5
  import pip
6
  from google.genai import types
 
7
 
8
  toolsImported = []
9
 
@@ -11,6 +12,8 @@ TOOLS_DIRECTORY = os.path.abspath("./tools")
11
 
12
  class Tool:
13
  def __init__(self, toolClass):
 
 
14
  self.tool = toolClass()
15
  self.inputSchema = self.tool.inputSchema
16
  self.name = self.inputSchema["name"]
@@ -24,6 +27,7 @@ class Tool:
24
  if '==' in package:
25
  package = package.split('==')[0]
26
  pip.main(['install', package])
 
27
 
28
  def run(self, query):
29
  return self.tool.run(**query)
@@ -35,6 +39,7 @@ class ToolLoader:
35
  pass
36
 
37
  def load_tools(self):
 
38
  for filename in os.listdir(TOOLS_DIRECTORY):
39
  if filename.endswith(".py") and filename != "__init__.py":
40
  module_name = filename[:-3]
 
4
  import types
5
  import pip
6
  from google.genai import types
7
+ import sys
8
 
9
  toolsImported = []
10
 
 
12
 
13
  class Tool:
14
  def __init__(self, toolClass):
15
+ save_stdout = sys.stdout
16
+ sys.stdout = open('trash', 'w')
17
  self.tool = toolClass()
18
  self.inputSchema = self.tool.inputSchema
19
  self.name = self.inputSchema["name"]
 
27
  if '==' in package:
28
  package = package.split('==')[0]
29
  pip.main(['install', package])
30
+ sys.stdout = save_stdout
31
 
32
  def run(self, query):
33
  return self.tool.run(**query)
 
39
  pass
40
 
41
  def load_tools(self):
42
+ self.toolsImported = []
43
  for filename in os.listdir(TOOLS_DIRECTORY):
44
  if filename.endswith(".py") and filename != "__init__.py":
45
  module_name = filename[:-3]
main.py CHANGED
@@ -20,7 +20,6 @@ def web_search(website: str, query: str) -> List[str]:
20
  return results
21
 
22
  if __name__ == "__main__":
23
- warnings.filterwarnings("ignore")
24
  # Define the tool metadata for orchestration.
25
  tools = [
26
  {
@@ -50,7 +49,7 @@ if __name__ == "__main__":
50
  # The prompt explicitly mentions that it can use the web_search tool if needed,
51
  # and that it is allowed to choose the website for the search.
52
  task_prompt = (
53
- "Create a strategy for Ashton Hall to improve its online presence."
54
  )
55
 
56
  # Request a CEO response with the prompt.
 
20
  return results
21
 
22
  if __name__ == "__main__":
 
23
  # Define the tool metadata for orchestration.
24
  tools = [
25
  {
 
49
  # The prompt explicitly mentions that it can use the web_search tool if needed,
50
  # and that it is allowed to choose the website for the search.
51
  task_prompt = (
52
+ "Get me the current AAPL stock price and the latest news about it. "
53
  )
54
 
55
  # Request a CEO response with the prompt.
tools/agent_creater_tool.py CHANGED
@@ -33,9 +33,6 @@ class AgentCreator():
33
  "required": ["agent_name", "base_model", "system_prompt", "description"],
34
  }
35
  }
36
-
37
- def __init__(self):
38
- pass
39
 
40
  def does_agent_exist(self, agent_name):
41
  ollama = importlib.import_module("ollama")
 
33
  "required": ["agent_name", "base_model", "system_prompt", "description"],
34
  }
35
  }
 
 
 
36
 
37
  def does_agent_exist(self, agent_name):
38
  ollama = importlib.import_module("ollama")
tools/arxiv_tool.py CHANGED
@@ -14,7 +14,12 @@ class ArxivTool():
14
  "properties": {
15
  "query": {
16
  "type": "string",
17
- "description": "Search query for papers (e.g., 'superconductors gem5').",
 
 
 
 
 
18
  },
19
  "max_results": {
20
  "type": "integer",
@@ -26,9 +31,6 @@ class ArxivTool():
26
  }
27
  }
28
 
29
- def __init__(self):
30
- pass
31
-
32
  def run(self, **kwargs):
33
  query = kwargs.get("query")
34
  max_results = kwargs.get("max_results", 5)
 
14
  "properties": {
15
  "query": {
16
  "type": "string",
17
+ "description": "Search query for papers on arXiv.",
18
+ "examples":[
19
+ "superconductors gem5",
20
+ "machine learning in healthcare",
21
+ "quantum computing algorithms"
22
+ ]
23
  },
24
  "max_results": {
25
  "type": "integer",
 
31
  }
32
  }
33
 
 
 
 
34
  def run(self, **kwargs):
35
  query = kwargs.get("query")
36
  max_results = kwargs.get("max_results", 5)
tools/ask_agent_tool.py CHANGED
@@ -27,9 +27,6 @@ class AskAgent():
27
  }
28
  }
29
 
30
- def __init__(self):
31
- pass
32
-
33
  def does_agent_exist(self, ollama, agent_name):
34
  all_agents = [a.model for a in ollama.list().models]
35
  if agent_name in all_agents or f'{agent_name}:latest' in all_agents:
 
27
  }
28
  }
29
 
 
 
 
30
  def does_agent_exist(self, ollama, agent_name):
31
  all_agents = [a.model for a in ollama.list().models]
32
  if agent_name in all_agents or f'{agent_name}:latest' in all_agents:
tools/ask_user.py CHANGED
@@ -21,9 +21,6 @@ class AskUser():
21
  }
22
  }
23
 
24
- def __init__(self):
25
- pass
26
-
27
  def run(self, **kwargs):
28
  print("Running Ask User tool")
29
  question = kwargs.get("question")
 
21
  }
22
  }
23
 
 
 
 
24
  def run(self, **kwargs):
25
  print("Running Ask User tool")
26
  question = kwargs.get("question")
tools/get_agents_tool.py CHANGED
@@ -16,9 +16,6 @@ class GetAgents():
16
  },
17
  }
18
 
19
- def __init__(self):
20
- pass
21
-
22
  def run(self, **kwargs):
23
  with open("./models/models.json", "r", encoding="utf8") as f:
24
  models = f.read()
 
16
  },
17
  }
18
 
 
 
 
19
  def run(self, **kwargs):
20
  with open("./models/models.json", "r", encoding="utf8") as f:
21
  models = f.read()
tools/get_website_tool.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import importlib
2
+
3
+ __all__ = ['GetWebsiteTool']
4
+
5
+
6
+ class GetWebsiteTool():
7
+ dependencies = ["requests"]
8
+
9
+ inputSchema = {
10
+ "name": "GetWebsiteTool",
11
+ "description": "Returns the content of a website based on a query string.",
12
+ "parameters": {
13
+ "type": "object",
14
+ "properties": {
15
+ "url": {
16
+ "type": "string",
17
+ "description": "The URL of the website to fetch content from.",
18
+ },
19
+ },
20
+ "required": ["url"],
21
+ }
22
+ }
23
+
24
+ def run(self, **kwargs):
25
+ print("Running web search")
26
+
27
+ url = kwargs.get("url")
28
+
29
+ if not url:
30
+ return {
31
+ "status": "error",
32
+ "message": "Missing required parameters: 'url'",
33
+ "output": None
34
+ }
35
+
36
+ output = None
37
+ requests = importlib.import_module("requests")
38
+ try:
39
+ response = requests.get(url)
40
+ if response.status_code == 200:
41
+ output = response.text
42
+ else:
43
+ return {
44
+ "status": "error",
45
+ "message": f"Failed to fetch content from {url}. Status code: {response.status_code}",
46
+ "output": None
47
+ }
48
+
49
+ # truncate the results to avoid excessive output
50
+ if len(output) > 1000:
51
+ output = output[:1000] + "... (truncated)"
52
+
53
+ return {
54
+ "status": "success",
55
+ "message": "Search completed successfully",
56
+ "output": output,
57
+ }
58
+ except Exception as e:
59
+ return {
60
+ "status": "error",
61
+ "message": str(e),
62
+ "output": None
63
+ }
tools/{web_search_tool.py → google_search_tool.py} RENAMED
@@ -1,14 +1,14 @@
1
  import importlib
2
 
3
- __all__ = ['WebSearchTool']
4
 
5
 
6
- class WebSearchTool():
7
  dependencies = ["googlesearch-python==1.3.0"]
8
 
9
  inputSchema = {
10
- "name": "WebSearchTool",
11
- "description": "Searches a specific website for a given query using Google search.",
12
  "parameters": {
13
  "type": "object",
14
  "properties": {
@@ -21,27 +21,26 @@ class WebSearchTool():
21
  "description": "The query string to search for on the website.",
22
  }
23
  },
24
- "required": ["website", "query"],
25
  }
26
  }
27
 
28
- def __init__(self):
29
- pass
30
-
31
  def run(self, **kwargs):
32
  print("Running web search")
33
 
34
  website = kwargs.get("website")
35
  query = kwargs.get("query")
36
 
37
- if not website or not query:
38
  return {
39
  "status": "error",
40
- "message": "Missing required parameters: 'website' and 'query'",
41
  "output": None
42
  }
43
-
44
- search_query = f"site:{website} {query}"
 
 
45
  results = []
46
 
47
  googlesearch = importlib.import_module("googlesearch")
 
1
  import importlib
2
 
3
+ __all__ = ['GoogleSearchTool']
4
 
5
 
6
+ class GoogleSearchTool():
7
  dependencies = ["googlesearch-python==1.3.0"]
8
 
9
  inputSchema = {
10
+ "name": "GoogleSearchTool",
11
+ "description": "Provides a list of URLs from google search results based on a query string.",
12
  "parameters": {
13
  "type": "object",
14
  "properties": {
 
21
  "description": "The query string to search for on the website.",
22
  }
23
  },
24
+ "required": ["query"],
25
  }
26
  }
27
 
 
 
 
28
  def run(self, **kwargs):
29
  print("Running web search")
30
 
31
  website = kwargs.get("website")
32
  query = kwargs.get("query")
33
 
34
+ if not query:
35
  return {
36
  "status": "error",
37
+ "message": "Missing required parameters: 'query'",
38
  "output": None
39
  }
40
+ search_query = query
41
+ if website:
42
+ search_query = f"site:{website} {query}"
43
+
44
  results = []
45
 
46
  googlesearch = importlib.import_module("googlesearch")
tools/list_files.py CHANGED
@@ -20,9 +20,6 @@ class ListFiles():
20
  }
21
  }
22
 
23
- def __init__(self):
24
- pass
25
-
26
  def run(self, **kwargs):
27
  print("Running List Files tool")
28
  directory = kwargs.get("directory")
 
20
  }
21
  }
22
 
 
 
 
23
  def run(self, **kwargs):
24
  print("Running List Files tool")
25
  directory = kwargs.get("directory")
tools/read_file.py CHANGED
@@ -21,9 +21,6 @@ class ReadFile():
21
  }
22
  }
23
 
24
- def __init__(self):
25
- pass
26
-
27
  def run(self, **kwargs):
28
  print("Running Read File tool")
29
  file_path = kwargs.get("file_path")
 
21
  }
22
  }
23
 
 
 
 
24
  def run(self, **kwargs):
25
  print("Running Read File tool")
26
  file_path = kwargs.get("file_path")
tools/tool_creator.py CHANGED
@@ -25,9 +25,6 @@ class ToolCreator():
25
  }
26
  }
27
 
28
- def __init__(self):
29
- pass
30
-
31
  def run(self, **kwargs):
32
  print("Running Tool Creator")
33
  name = kwargs.get("name")
 
25
  }
26
  }
27
 
 
 
 
28
  def run(self, **kwargs):
29
  print("Running Tool Creator")
30
  name = kwargs.get("name")
tools/weather_tool.py CHANGED
@@ -21,9 +21,6 @@ class WeatherApi():
21
  }
22
  }
23
 
24
- def __init__(self):
25
- pass
26
-
27
  def run(self, **kwargs):
28
  print("Running Weather API test tool")
29
  location = kwargs.get("location")
 
21
  }
22
  }
23
 
 
 
 
24
  def run(self, **kwargs):
25
  print("Running Weather API test tool")
26
  location = kwargs.get("location")
tools/wikipedia_tool.py CHANGED
@@ -21,9 +21,6 @@ class WikipediaTool():
21
  }
22
  }
23
 
24
- def __init__(self):
25
- pass
26
-
27
  def run(self, **kwargs):
28
  question = kwargs.get("question")
29
  if not question:
 
21
  }
22
  }
23
 
 
 
 
24
  def run(self, **kwargs):
25
  question = kwargs.get("question")
26
  if not question: