Spaces:
Sleeping
Sleeping
Kunal Pai commited on
Commit ·
27b38ea
1
Parent(s): d2c2786
Refactor GeminiManager to accept model name as a parameter and update role assignment logic
Browse files- CEO/CEO.py +9 -4
- main.py +1 -1
CEO/CEO.py
CHANGED
|
@@ -6,18 +6,22 @@ from dotenv import load_dotenv
|
|
| 6 |
from CEO.tool_loader import ToolLoader
|
| 7 |
|
| 8 |
class GeminiManager:
|
| 9 |
-
def __init__(self, toolsLoader: ToolLoader, system_prompt_file="./models/system2.prompt"):
|
| 10 |
load_dotenv()
|
| 11 |
self.API_KEY = os.getenv("GEMINI_KEY")
|
| 12 |
self.client = genai.Client(api_key=self.API_KEY)
|
| 13 |
self.toolsLoader = toolsLoader
|
| 14 |
self.toolsLoader.load_tools()
|
|
|
|
| 15 |
with open(system_prompt_file, 'r', encoding="utf8") as f:
|
| 16 |
self.system_prompt = f.read()
|
| 17 |
|
| 18 |
def request(self, messages):
|
| 19 |
response = self.client.models.generate_content(
|
| 20 |
-
model='gemini-2.5-pro-preview-03-25',
|
|
|
|
|
|
|
|
|
|
| 21 |
contents=messages,
|
| 22 |
config=types.GenerateContentConfig(
|
| 23 |
system_instruction=self.system_prompt,
|
|
@@ -30,7 +34,7 @@ class GeminiManager:
|
|
| 30 |
|
| 31 |
if response.text is not None:
|
| 32 |
assistant_content = types.Content(
|
| 33 |
-
role='assistant',
|
| 34 |
parts=[types.Part.from_text(text=response.text)],
|
| 35 |
)
|
| 36 |
messages.append(assistant_content)
|
|
@@ -57,7 +61,8 @@ class GeminiManager:
|
|
| 57 |
response={"result":"New tool doesn't follow the required format, please read the other tool implementations for reference." + str(e)})
|
| 58 |
parts.append(tool_content)
|
| 59 |
function_response_content = types.Content(
|
| 60 |
-
role='
|
|
|
|
| 61 |
)
|
| 62 |
messages.append(function_response_content)
|
| 63 |
self.request(messages)
|
|
|
|
| 6 |
from CEO.tool_loader import ToolLoader
|
| 7 |
|
| 8 |
class GeminiManager:
|
| 9 |
+
def __init__(self, toolsLoader: ToolLoader, system_prompt_file="./models/system2.prompt", gemini_model="gemini-2.5-pro-exp-03-25"):
|
| 10 |
load_dotenv()
|
| 11 |
self.API_KEY = os.getenv("GEMINI_KEY")
|
| 12 |
self.client = genai.Client(api_key=self.API_KEY)
|
| 13 |
self.toolsLoader = toolsLoader
|
| 14 |
self.toolsLoader.load_tools()
|
| 15 |
+
self.model_name = gemini_model
|
| 16 |
with open(system_prompt_file, 'r', encoding="utf8") as f:
|
| 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,
|
|
|
|
| 34 |
|
| 35 |
if response.text is not None:
|
| 36 |
assistant_content = types.Content(
|
| 37 |
+
role='model' if self.model_name == "gemini-2.5-pro-exp-03-25" else 'assistant',
|
| 38 |
parts=[types.Part.from_text(text=response.text)],
|
| 39 |
)
|
| 40 |
messages.append(assistant_content)
|
|
|
|
| 61 |
response={"result":"New tool doesn't follow the required format, please read the other tool implementations for reference." + str(e)})
|
| 62 |
parts.append(tool_content)
|
| 63 |
function_response_content = types.Content(
|
| 64 |
+
role='model' if self.model_name == "gemini-2.5-pro-exp-03-25" else 'tool',
|
| 65 |
+
parts=parts
|
| 66 |
)
|
| 67 |
messages.append(function_response_content)
|
| 68 |
self.request(messages)
|
main.py
CHANGED
|
@@ -44,7 +44,7 @@ if __name__ == "__main__":
|
|
| 44 |
# Load the tools using the ToolLoader class.
|
| 45 |
tool_loader = ToolLoader()
|
| 46 |
|
| 47 |
-
model_manager = GeminiManager(toolsLoader=tool_loader)
|
| 48 |
|
| 49 |
# Example prompt instructing the CEO model to create a strategy for Ashton Hall.
|
| 50 |
# The prompt explicitly mentions that it can use the web_search tool if needed,
|
|
|
|
| 44 |
# Load the tools using the ToolLoader class.
|
| 45 |
tool_loader = ToolLoader()
|
| 46 |
|
| 47 |
+
model_manager = GeminiManager(toolsLoader=tool_loader, gemini_model="gemini-2.5-pro-exp-03-25")
|
| 48 |
|
| 49 |
# Example prompt instructing the CEO model to create a strategy for Ashton Hall.
|
| 50 |
# The prompt explicitly mentions that it can use the web_search tool if needed,
|