From fc9c2d2ea1928c1511e13850d4c173a0ef9c08b9 Mon Sep 17 00:00:00 2001 From: Kye Date: Fri, 28 Jul 2023 13:14:28 -0400 Subject: [PATCH] clean up Former-commit-id: f0130e1aca4c38a9d6dd922c482f6568690d04e2 --- setup.py | 2 +- swarms/agents/agent_prompt.py | 78 ----------------------------------- swarms/swarms.py | 19 +++------ 3 files changed, 6 insertions(+), 93 deletions(-) delete mode 100644 swarms/agents/agent_prompt.py diff --git a/setup.py b/setup.py index dcfd92de..a762d29f 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup, find_packages setup( name = 'swarms', packages = find_packages(exclude=[]), - version = '1.1.1', + version = '1.1.2', license='MIT', description = 'Swarms - Pytorch', author = 'Kye Gomez', diff --git a/swarms/agents/agent_prompt.py b/swarms/agents/agent_prompt.py deleted file mode 100644 index 30a1cfb9..00000000 --- a/swarms/agents/agent_prompt.py +++ /dev/null @@ -1,78 +0,0 @@ -import json -from typing import List - -class PromptGenerator: - """A class for generating custom prompt strings.""" - - def __init__(self) -> None: - """Initialize the PromptGenerator object.""" - self.constraints: List[str] = [] - self.commands: List[str] = [] - self.resources: List[str] = [] - self.performance_evaluation: List[str] = [] - self.response_format = { - "thoughts": { - "text": "thought", - "reasoning": "reasoning", - "plan": "- short bulleted\n- list that conveys\n- long-term plan", - "criticism": "constructive self-criticism", - "speak": "thoughts summary to say to user", - }, - "command": {"name": "command name", "args": {"arg name": "value"}}, - } - - def add_constraint(self, constraint: str) -> None: - """ - Add a constraint to the constraints list. - - Args: - constraint (str): The constraint to be added. - """ - self.constraints.append(constraint) - - def add_command(self, command: str) -> None: - """ - Add a command to the commands list. - - Args: - command (str): The command to be added. - """ - self.commands.append(command) - - def add_resource(self, resource: str) -> None: - """ - Add a resource to the resources list. - - Args: - resource (str): The resource to be added. - """ - self.resources.append(resource) - - def add_performance_evaluation(self, evaluation: str) -> None: - """ - Add a performance evaluation item to the performance_evaluation list. - - Args: - evaluation (str): The evaluation item to be added. - """ - self.performance_evaluation.append(evaluation) - - def generate_prompt_string(self) -> str: - """Generate a prompt string. - - Returns: - str: The generated prompt string. - """ - formatted_response_format = json.dumps(self.response_format, indent=4) - prompt_string = ( - f"Constraints:\n{''.join(self.constraints)}\n\n" - f"Commands:\n{''.join(self.commands)}\n\n" - f"Resources:\n{''.join(self.resources)}\n\n" - f"Performance Evaluation:\n{''.join(self.performance_evaluation)}\n\n" - f"You should only respond in JSON format as described below " - f"\nResponse Format: \n{formatted_response_format} " - f"\nEnsure the response can be parsed by Python json.loads" - ) - - return prompt_string - diff --git a/swarms/swarms.py b/swarms/swarms.py index 02c3f70f..bde70930 100644 --- a/swarms/swarms.py +++ b/swarms/swarms.py @@ -14,7 +14,6 @@ from langchain.tools.file_management.read import ReadFileTool from langchain.tools.file_management.write import WriteFileTool from langchain.vectorstores import FAISS -from swarms.agents.models.hf import HuggingFaceLLM # from langchain.tools.human.tool import HumanInputRun from swarms.agents.tools.main import WebpageQATool, process_csv @@ -38,7 +37,6 @@ ROOT_DIR = "./data/" class HierarchicalSwarm: def __init__( self, - model_id: Optional[str] = None, openai_api_key: Optional[str] = "", use_vectorstore: Optional[bool] = True, @@ -46,21 +44,18 @@ class HierarchicalSwarm: use_async: Optional[bool] = True, human_in_the_loop: Optional[bool] = True, - model_type: Optional[str] = None, boss_prompt: Optional[str] = None, worker_prompt: Optional[str] = None, temperature: Optional[float] = None, max_iterations: Optional[int] = None, logging_enabled: Optional[bool] = True): - - self.model_id = model_id + self.openai_api_key = openai_api_key self.use_vectorstore = use_vectorstore self.use_async = use_async self.human_in_the_loop = human_in_the_loop - self.model_type = model_type self.embedding_size = embedding_size self.boss_prompt = boss_prompt @@ -86,10 +81,7 @@ class HierarchicalSwarm: """ try: # Initialize language model - if self.llm_class == 'openai': - return OpenAI(openai_api_key=self.openai_api_key, temperature=self.temperature) - elif self.model_type == "huggingface": - return HuggingFaceLLM(model_id=self.model_id, temperature=self.temperature) + return OpenAI(openai_api_key=self.openai_api_key, temperature=self.temperature) except Exception as e: logging.error(f"Failed to initialize language model: {e}") @@ -197,7 +189,8 @@ class HierarchicalSwarm: agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=[tool.name for tool in tools]) agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=verbose) - return BossNode(llm, vectorstore, agent_executor, max_iterations=self.max_iterations) + return BossNode(llm, vectorstore, + agent_executor, max_iterations=self.max_iterations) except Exception as e: logging.error(f"Failed to initialize boss node: {e}") raise @@ -239,8 +232,6 @@ class HierarchicalSwarm: def swarm( api_key: Optional[str]="", objective: Optional[str]="", - model_type: Optional[str]="", - model_id: Optional[str]="" ): """ Run the swarm with the given API key and objective. @@ -260,7 +251,7 @@ def swarm( logging.error("Invalid objective") raise ValueError("A valid objective is required") try: - swarms = HierarchicalSwarm(api_key, model_id=model_type, use_async=False, model_type=model_type) #logging_enabled=logging_enabled) # Turn off async + swarms = HierarchicalSwarm(api_key, use_async=False) #logging_enabled=logging_enabled) # Turn off async result = swarms.run(objective) if result is None: logging.error("Failed to run swarms")