From c3b61a97bc227acdeae40a04a3fa4adfa55685cc Mon Sep 17 00:00:00 2001 From: Kye Date: Tue, 26 Sep 2023 18:42:45 -0400 Subject: [PATCH] init clean up Former-commit-id: 8c7032ffcda37d91d2a073554f5792b1a93a0989 --- example_godmode.py | 2 +- swarms/__init__.py | 13 +-- swarms/structs/__init__.py | 3 + swarms/workers/__init__.py | 1 + swarms/workers/worker_ultra_node.py | 123 ---------------------------- 5 files changed, 8 insertions(+), 134 deletions(-) delete mode 100644 swarms/workers/worker_ultra_node.py diff --git a/example_godmode.py b/example_godmode.py index e9f3bca5..b4ac0333 100644 --- a/example_godmode.py +++ b/example_godmode.py @@ -1,6 +1,6 @@ from swarms.models import Anthropic, GooglePalm, OpenAIChat -from swarms.swarms.god_mode import GodMode +from swarms.swarms import GodMode claude = Anthropic(anthropic_api_key="") palm = GooglePalm(google_api_key="") diff --git a/swarms/__init__.py b/swarms/__init__.py index e118f67d..8c105356 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -2,11 +2,8 @@ from swarms.logo import logo2 print(logo2) -#from swarms.orchestrator.autoscaler import AutoScaler - # worker -# from swarms.workers.worker_node import WorkerNode -from swarms.workers.worker import Worker +import swarms.workers #boss # from swarms.boss.boss_node import Boss @@ -15,14 +12,10 @@ from swarms.workers.worker import Worker import swarms.models #structs -from swarms.structs.workflow import Workflow -from swarms.structs.task import Task +import swarms.structs # swarms import swarms.swarms #agents -from swarms.swarms.profitpilot import ProfitPilot -from swarms.agents.aot_agent import AOTAgent -from swarms.agents.multi_modal_agent import MultiModalVisualAgent -from swarms.agents.omni_modal_agent import OmniModalAgent \ No newline at end of file +import swarms.agents \ No newline at end of file diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index e69de29b..9344c3a0 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -0,0 +1,3 @@ +#structs +from swarms.structs.workflow import Workflow +from swarms.structs.task import Task \ No newline at end of file diff --git a/swarms/workers/__init__.py b/swarms/workers/__init__.py index e69de29b..b1d878cf 100644 --- a/swarms/workers/__init__.py +++ b/swarms/workers/__init__.py @@ -0,0 +1 @@ +from swarms.workers.worker import Worker \ No newline at end of file diff --git a/swarms/workers/worker_ultra_node.py b/swarms/workers/worker_ultra_node.py deleted file mode 100644 index 143009bf..00000000 --- a/swarms/workers/worker_ultra_node.py +++ /dev/null @@ -1,123 +0,0 @@ -import logging -import os -import re -from pathlib import Path -from typing import Dict, List - -from swarms.agents.utils.agent_creator import AgentCreator -from swarms.tools.main import ( - BaseToolSet, - CodeEditor, - ExitConversation, - RequestsGet, - Terminal, -) -from swarms.utils.main import ( - BaseHandler, - CsvToDataframe, - FileHandler, - FileType, - StaticUploader, -) - -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -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') -# Ensure the path exists before changing the directory -os.makedirs(BASE_DIR / playground, exist_ok=True) - -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 - - if not isinstance(objective, str): - raise TypeError("Objective must be a string") - if not objective: - raise ValueError("Objective cannot be empty") - - toolsets: List[BaseToolSet] = [ - Terminal(), - CodeEditor(), - RequestsGet(), - ExitConversation(), - ] - handlers: Dict[FileType, BaseHandler] = {FileType.DATAFRAME: CsvToDataframe()} - - if os.environ.get("USE_GPU", False): - import torch - - from swarms.tools.main import ( - ImageCaptioning, - ImageEditing, - InstructPix2Pix, - Text2Image, - VisualQuestionAnswering, - ) - - if torch.cuda.is_available(): - toolsets.extend( - [ - Text2Image("cuda"), - ImageEditing("cuda"), - InstructPix2Pix("cuda"), - VisualQuestionAnswering("cuda"), - ] - ) - handlers[FileType.IMAGE] = ImageCaptioning("cuda") - - try: - self.agent_manager = AgentCreator.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: - logging.error(f"Error while initializing WorkerUltraNode: {str(e)}") - raise e - - def execute_task(self): - # Now the prompt is not needed as an argument - promptedQuery = self.file_handler.handle(self.objective) - - try: - res = self.session({"input": promptedQuery}) - except Exception as e: - logging.error(f"Error while executing task: {str(e)}") - return {"answer": str(e), "files": []} - - files = re.findall(r"\[file://\S*\]", res["output"]) - files = [file[1:-1].split("file://")[1] for file in files] - - return { - "answer": res["output"], - "files": [self.uploader.upload(file) for file in files], - } - - def execute(self): - try: - return self.execute_task() - except Exception as e: - logging.error(f"Error while executing: {str(e)}") - raise e - -class WorkerUltra: - def __init__(self, objective, api_key=None): - self.api_key = api_key or os.getenv('OPENAI_API_KEY') - if not self.api_key: - raise ValueError("API key must be provided either as argument or as an environment variable named 'OPENAI_API_KEY'.") - self.worker_node = WorkerUltraNode(objective, self.api_key) - - def execute(self): - try: - return self.worker_node.execute_task() - except Exception as e: - logging.error(f"Error while executing: {str(e)}") - raise e \ No newline at end of file