From 29df2d174a62b8c1cd73645cf816f119fc1ace19 Mon Sep 17 00:00:00 2001 From: Kye Date: Sun, 16 Jul 2023 15:49:18 -0400 Subject: [PATCH] clean up with worker ultra node Former-commit-id: 3cfa2a869a6af22557466932488e36039ffdc653 --- swarms/agents/workers/WorkerUltraNode.py | 31 ++---------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/swarms/agents/workers/WorkerUltraNode.py b/swarms/agents/workers/WorkerUltraNode.py index 90179b97..10eb0459 100644 --- a/swarms/agents/workers/WorkerUltraNode.py +++ b/swarms/agents/workers/WorkerUltraNode.py @@ -6,16 +6,14 @@ from typing import Dict, List from swarms.agents.utils.AgentManager import AgentManager from swarms.utils.main import BaseHandler, FileHandler, FileType - from swarms.tools.main import ExitConversation, RequestsGet, CodeEditor, Terminal from swarms.utils.main import CsvToDataframe - from swarms.tools.main import BaseToolSet from swarms.utils.main import StaticUploader logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -BASE_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +BASE_DIR = Path(__file__).resolve().parent.parent # Check if "PLAYGROUND_DIR" environment variable exists, if not, set a default value playground = os.environ.get("PLAYGROUND_DIR", './playground') @@ -27,7 +25,7 @@ try: os.chdir(BASE_DIR / playground) except Exception as e: logging.error(f"Failed to change directory: {e}") - + class WorkerUltraNode: def __init__(self, objective: str, openai_api_key: str): self.openai_api_key = openai_api_key @@ -62,15 +60,11 @@ class WorkerUltraNode: handlers[FileType.IMAGE] = ImageCaptioning("cuda") try: - - self.agent_manager = AgentManager.create(toolsets=toolsets) self.file_handler = FileHandler(handlers=handlers, path=BASE_DIR) self.uploader = StaticUploader.from_settings( path=BASE_DIR / "static", endpoint="static" ) - - self.session = self.agent_manager.create_executor(objective, self.openai_api_key) except Exception as e: @@ -95,32 +89,13 @@ class WorkerUltraNode: "files": [self.uploader.upload(file) for file in files], } - def execute(self): try: - - # The prompt is not needed here either return self.execute_task() except Exception as e: logging.error(f"Error while executing: {str(e)}") raise e - - -# def WorkerUltra(objective: str, openai_api_key=None): -# # If the openai_api_key parameter is not provided, try to get the API key from an environment variable # -# if openai_api_key is None: -# openai_api_key = os.getenv('OPENAI_API_KEY') - -# if not openai_api_key or not isinstance(openai_api_key, str): -# logging.error("Invalid OpenAI key") -# raise ValueError("A valid OpenAI API key is required") - -# worker_node = WorkerUltraNode(objective, openai_api_key) -# # Return the result of the execution -# return worker_node.result - - class WorkerUltra: def __init__(self, objective, api_key=None): self.api_key = api_key or os.getenv('OPENAI_API_KEY') @@ -134,5 +109,3 @@ class WorkerUltra: except Exception as e: logging.error(f"Error while executing: {str(e)}") raise e - -