From 5e8cdf9cec0a05beae0ff88d94de44fd5a8d344c Mon Sep 17 00:00:00 2001 From: Kye Date: Sat, 22 Jul 2023 12:48:13 -0400 Subject: [PATCH] clean up Former-commit-id: 4bca1d51cf0154b1ecee9262001f3b4750b87192 --- setup.py | 2 +- swarms/agents/boss/BossNode.py | 1 + swarms/agents/tools/main.py | 26 +++++++++++++------------- swarms/swarms.py | 21 ++++++++++++++++++--- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/setup.py b/setup.py index 8800fc9d..ae010e1a 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.9.0', + version = '1.0.0', license='MIT', description = 'Swarms - Pytorch', author = 'Kye Gomez', diff --git a/swarms/agents/boss/BossNode.py b/swarms/agents/boss/BossNode.py index 68462f3b..5ccb0b7d 100644 --- a/swarms/agents/boss/BossNode.py +++ b/swarms/agents/boss/BossNode.py @@ -26,6 +26,7 @@ class BossNodeInitializer: vectorstore=self.vectorstore, task_execution_chain=self.agent_executor, max_iterations=self.max_iterations, + human_in_the_loop=True ) except ValidationError as e: logging.error(f"Validation Error while initializing BabyAGI: {e}") diff --git a/swarms/agents/tools/main.py b/swarms/agents/tools/main.py index f50dc286..8397605d 100644 --- a/swarms/agents/tools/main.py +++ b/swarms/agents/tools/main.py @@ -2303,19 +2303,19 @@ list_tool.run({}) # raise NotImplementedError("transcribe_audio does not support async") ###########=========================> -#======> Calculator -from langchain import LLMMathChain - -llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True) -math_tool = Tool( - name="Calculator", - func=llm_math_chain.run, - description="useful for when you need to answer questions about math" - ), - -#####==========================================================================> TOOLS -from langchain.tools.human.tool import HumanInputRun -from langchain.tools import BaseTool, DuckDuckGoSearchRun +# #======> Calculator +# from langchain import LLMMathChain + +# llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True) +# math_tool = Tool( +# name="Calculator", +# func=llm_math_chain.run, +# description="useful for when you need to answer questions about math" +# ), + +# #####==========================================================================> TOOLS +# from langchain.tools.human.tool import HumanInputRun +# from langchain.tools import BaseTool, DuckDuckGoSearchRun diff --git a/swarms/swarms.py b/swarms/swarms.py index de0e0aa1..af814247 100644 --- a/swarms/swarms.py +++ b/swarms/swarms.py @@ -7,6 +7,9 @@ from swarms.agents.workers.WorkerNode import WorkerNodeInitializer, worker_node from swarms.agents.boss.BossNode import BossNodeInitializer as BossNode from swarms.agents.workers.worker_ultra_node import WorkerUltra +from langchain import LLMMathChain + + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') @@ -88,7 +91,7 @@ class Swarms: logging.error(f"Failed to initialize vector store: {e}") return None - def initialize_worker_node(self, worker_tools, vectorstore, llm_class=ChatOpenAI, ai_name="Swarm Worker AI Assistant"): + def initialize_worker_node(self, worker_tools, vectorstore, llm_class=ChatOpenAI, ai_name="Swarm Worker AI Assistant", human_in_the_loop=True): """ Init WorkerNode @@ -104,7 +107,7 @@ class Swarms: # Initialize worker node llm = self.initialize_llm(ChatOpenAI) worker_node = WorkerNodeInitializer(llm=llm, tools=worker_tools, vectorstore=vectorstore) - worker_node.create_agent(ai_name=ai_name, ai_role="Assistant", human_in_the_loop=False, search_kwargs={}) # add search kwargs + worker_node.create_agent(ai_name=ai_name, ai_role="Assistant", human_in_the_loop=False, search_kwargs={}, human_in_the_loop=human_in_the_loop) # add search kwargs worker_node_tool = Tool(name="WorkerNode AI Agent", func=worker_node.run, description="Input: an objective with a todo list for that objective. Output: your task completed: Please be very clear what the objective and task instructions are. The Swarm worker agent is Useful for when you need to spawn an autonomous agent instance as a worker to accomplish any complex tasks, it can search the internet or write code or spawn child multi-modality models to process and generate images and text or audio and so on") return worker_node_tool @@ -131,10 +134,20 @@ class Swarms: todo_prompt = PromptTemplate.from_template("You are a boss planer in a swarm who is an expert at coming up with a todo list for a given objective and then creating an worker to help you accomplish your task. Rate every task on the importance of it's probability to complete the main objective on a scale from 0 to 1, an integer. Come up with a todo list for this objective: {objective} and then spawn a worker agent to complete the task for you. Always spawn an worker agent after creating a plan and pass the objective and plan to the worker agent.") todo_chain = LLMChain(llm=llm, prompt=todo_prompt) + #math tool + llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True) + math_tool = Tool( + name="Calculator", + func=llm_math_chain.run, + description="useful for when you need to answer questions about math" + ), + tools = [ Tool(name="TODO", func=todo_chain.run, description="useful for when you need to come up with todo lists. Input: an objective to create a todo list for your objective. Note create a todo list then assign a ranking from 0.0 to 1.0 to each task, then sort the tasks based on the tasks most likely to achieve the objective. The Output: a todo list for that objective with rankings for each step from 0.1 Please be very clear what the objective is!"), - worker_node + worker_node, + math_tool ] + suffix = """Question: {task}\n{agent_scratchpad}""" prefix = """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 """ @@ -211,3 +224,5 @@ def swarm(api_key="", objective=""): except Exception as e: logging.error(f"An error occured in swarm: {e}") return None + +