Commit
·
f8d05a7
1
Parent(s):
18aba36
Improvements to the tools
Browse files- CEO/CEO.py +19 -4
- main.py +1 -1
- tools/get_website_tool.py +7 -2
CEO/CEO.py
CHANGED
@@ -47,8 +47,6 @@ class GeminiManager:
|
|
47 |
parts=[types.Part.from_text(text=response.text)],
|
48 |
)
|
49 |
messages.append(assistant_content)
|
50 |
-
if "EOF" in response.text:
|
51 |
-
return messages
|
52 |
if response.candidates[0].content:
|
53 |
messages.append(response.candidates[0].content)
|
54 |
if response.function_calls:
|
@@ -56,7 +54,15 @@ class GeminiManager:
|
|
56 |
for function_call in response.function_calls:
|
57 |
toolResponse = None
|
58 |
print(f"Function Name: {function_call.name}, Arguments: {function_call.args}")
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
print(f"Tool Response: {toolResponse}")
|
61 |
tool_content = types.Part.from_function_response(
|
62 |
name=function_call.name,
|
@@ -82,4 +88,13 @@ class GeminiManager:
|
|
82 |
return messages
|
83 |
else:
|
84 |
print("No tool calls found in the response.")
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
parts=[types.Part.from_text(text=response.text)],
|
48 |
)
|
49 |
messages.append(assistant_content)
|
|
|
|
|
50 |
if response.candidates[0].content:
|
51 |
messages.append(response.candidates[0].content)
|
52 |
if response.function_calls:
|
|
|
54 |
for function_call in response.function_calls:
|
55 |
toolResponse = None
|
56 |
print(f"Function Name: {function_call.name}, Arguments: {function_call.args}")
|
57 |
+
try:
|
58 |
+
toolResponse = self.toolsLoader.runTool(function_call.name, function_call.args)
|
59 |
+
except Exception as e:
|
60 |
+
print(f"Error running tool: {e}")
|
61 |
+
toolResponse = {
|
62 |
+
"status": "error",
|
63 |
+
"message": f"Tool {function_call.name} failed to run.",
|
64 |
+
"output": str(e),
|
65 |
+
}
|
66 |
print(f"Tool Response: {toolResponse}")
|
67 |
tool_content = types.Part.from_function_response(
|
68 |
name=function_call.name,
|
|
|
88 |
return messages
|
89 |
else:
|
90 |
print("No tool calls found in the response.")
|
91 |
+
question = input("User: ")
|
92 |
+
if ("exit" in question.lower() or "quit" in question.lower()):
|
93 |
+
print("Ending the conversation.")
|
94 |
+
return messages
|
95 |
+
user_content = types.Content(
|
96 |
+
role='user',
|
97 |
+
parts=[types.Part.from_text(text=question)],
|
98 |
+
)
|
99 |
+
messages.append(user_content)
|
100 |
+
return self.request(messages)
|
main.py
CHANGED
@@ -46,7 +46,7 @@ if __name__ == "__main__":
|
|
46 |
model_manager = GeminiManager(toolsLoader=tool_loader, gemini_model="gemini-2.0-flash")
|
47 |
|
48 |
task_prompt = (
|
49 |
-
"
|
50 |
)
|
51 |
|
52 |
# Request a CEO response with the prompt.
|
|
|
46 |
model_manager = GeminiManager(toolsLoader=tool_loader, gemini_model="gemini-2.0-flash")
|
47 |
|
48 |
task_prompt = (
|
49 |
+
"When did trumpcoin peak in price? "
|
50 |
)
|
51 |
|
52 |
# Request a CEO response with the prompt.
|
tools/get_website_tool.py
CHANGED
@@ -4,7 +4,7 @@ __all__ = ['GetWebsiteTool']
|
|
4 |
|
5 |
|
6 |
class GetWebsiteTool():
|
7 |
-
dependencies = ["requests"]
|
8 |
|
9 |
inputSchema = {
|
10 |
"name": "GetWebsiteTool",
|
@@ -35,10 +35,15 @@ class GetWebsiteTool():
|
|
35 |
|
36 |
output = None
|
37 |
requests = importlib.import_module("requests")
|
|
|
|
|
38 |
try:
|
39 |
response = requests.get(url)
|
40 |
if response.status_code == 200:
|
41 |
-
|
|
|
|
|
|
|
42 |
else:
|
43 |
return {
|
44 |
"status": "error",
|
|
|
4 |
|
5 |
|
6 |
class GetWebsiteTool():
|
7 |
+
dependencies = ["requests", "beautifulsoup4==4.13.3"]
|
8 |
|
9 |
inputSchema = {
|
10 |
"name": "GetWebsiteTool",
|
|
|
35 |
|
36 |
output = None
|
37 |
requests = importlib.import_module("requests")
|
38 |
+
bs4 = importlib.import_module("bs4")
|
39 |
+
BeautifulSoup = bs4.BeautifulSoup
|
40 |
try:
|
41 |
response = requests.get(url)
|
42 |
if response.status_code == 200:
|
43 |
+
# Parse the content using BeautifulSoup
|
44 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
45 |
+
# Extract text from the parsed HTML
|
46 |
+
output = soup.get_text()
|
47 |
else:
|
48 |
return {
|
49 |
"status": "error",
|