From b6e284b29830092bb83e543e0635c61b1674f2c6 Mon Sep 17 00:00:00 2001 From: Kye Date: Mon, 25 Sep 2023 13:00:07 -0400 Subject: [PATCH] clean up --- mmi.py | 5 +++ swarms/swarms/swarms.py | 96 ----------------------------------------- 2 files changed, 5 insertions(+), 96 deletions(-) create mode 100644 mmi.py delete mode 100644 swarms/swarms/swarms.py diff --git a/mmi.py b/mmi.py new file mode 100644 index 00000000..85df7938 --- /dev/null +++ b/mmi.py @@ -0,0 +1,5 @@ +from swarms import DialogueSimulator, Worker + +collab = DialogueSimulator(Worker, DialogueSimulator.select_next_speaker) +collab.start("My name is Plinus and I am a worker", "How are you?") + diff --git a/swarms/swarms/swarms.py b/swarms/swarms/swarms.py deleted file mode 100644 index 1e311a2b..00000000 --- a/swarms/swarms/swarms.py +++ /dev/null @@ -1,96 +0,0 @@ -import asyncio -import logging -from typing import Optional - -from langchain import OpenAI - -from swarms.boss.boss_node import Boss -from swarms.workers.worker import Worker - -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') - -# ---------- Constants ---------- -ROOT_DIR = "./data/" - -class HierarchicalSwarm: - def __init__( - self, - openai_api_key: Optional[str] = "", - use_vectorstore: Optional[bool] = True, - use_async: Optional[bool] = True, - worker_name: Optional[str] = "Swarm Worker AI Assistant", - verbose: Optional[bool] = False, - human_in_the_loop: Optional[bool] = True, - boss_prompt: Optional[str] = "You are an Boss in a swarm who performs one task based on the following objective: {objective}. Take into account these previously completed tasks: {context}.\n", - worker_prompt: Optional[str] = None, - temperature: Optional[float] = 0.5, - max_iterations: Optional[int] = None, - logging_enabled: Optional[bool] = True - ): - self.openai_api_key = openai_api_key - self.use_vectorstore = use_vectorstore - self.use_async = use_async - self.worker_name = worker_name - self.human_in_the_loop = human_in_the_loop - self.boss_prompt = boss_prompt - self.temperature = temperature - self.max_iterations = max_iterations - self.logging_enabled = logging_enabled - self.verbose = verbose - - self.worker_node = Worker( - openai_api_key=self.openai_api_key, - temperature=self.temperature, - human_in_the_loop=self.human_in_the_loop, - verbose=self.verbose - ) - - self.boss_node = Boss( - api_key=self.openai_api_key, - worker_node=self.worker_node, - llm_class=OpenAI, - max_iterations=self.max_iterations, - verbose=self.verbose - ) - - self.logger = logging.getLogger() - if not logging_enabled: - self.logger.disabled = True - - def run(self, objective): - try: - self.boss_node.task = self.boss_node.create_task(objective) - logging.info(f"Running task: {self.boss_node.task}") - if self.use_async: - loop = asyncio.get_event_loop() - result = loop.run_until_complete(self.boss_node.run()) - else: - result = self.boss_node.run() - logging.info(f"Completed tasks: {self.boss_node.task}") - return result - except Exception as e: - logging.error(f"An error occurred in run: {e}") - return None - -def swarm( - api_key: Optional[str]="", - objective: Optional[str]="" -): - if not api_key or not isinstance(api_key, str): - logging.error("Invalid OpenAI key") - raise ValueError("A valid OpenAI API key is required") - if not objective or not isinstance(objective, str): - logging.error("Invalid objective") - raise ValueError("A valid objective is required") - try: - swarms = HierarchicalSwarm(api_key, use_async=False) - result = swarms.run(objective) - if result is None: - logging.error("Failed to run swarms") - else: - logging.info(f"Successfully ran swarms with results: {result}") - return result - except Exception as e: - logging.error(f"An error occured in swarm: {e}") - return None - \ No newline at end of file