Former-commit-id: 4bca1d51cf
huggingface
Kye 1 year ago
parent 4ea6fc0222
commit 5e8cdf9cec

@ -4,7 +4,7 @@ from setuptools import setup, find_packages
setup( setup(
name = 'swarms', name = 'swarms',
packages = find_packages(exclude=[]), packages = find_packages(exclude=[]),
version = '1.9.0', version = '1.0.0',
license='MIT', license='MIT',
description = 'Swarms - Pytorch', description = 'Swarms - Pytorch',
author = 'Kye Gomez', author = 'Kye Gomez',

@ -26,6 +26,7 @@ class BossNodeInitializer:
vectorstore=self.vectorstore, vectorstore=self.vectorstore,
task_execution_chain=self.agent_executor, task_execution_chain=self.agent_executor,
max_iterations=self.max_iterations, max_iterations=self.max_iterations,
human_in_the_loop=True
) )
except ValidationError as e: except ValidationError as e:
logging.error(f"Validation Error while initializing BabyAGI: {e}") logging.error(f"Validation Error while initializing BabyAGI: {e}")

@ -2303,19 +2303,19 @@ list_tool.run({})
# raise NotImplementedError("transcribe_audio does not support async") # raise NotImplementedError("transcribe_audio does not support async")
###########=========================> ###########=========================>
#======> Calculator # #======> Calculator
from langchain import LLMMathChain # from langchain import LLMMathChain
llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True) # llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True)
math_tool = Tool( # math_tool = Tool(
name="Calculator", # name="Calculator",
func=llm_math_chain.run, # func=llm_math_chain.run,
description="useful for when you need to answer questions about math" # description="useful for when you need to answer questions about math"
), # ),
#####==========================================================================> TOOLS # #####==========================================================================> TOOLS
from langchain.tools.human.tool import HumanInputRun # from langchain.tools.human.tool import HumanInputRun
from langchain.tools import BaseTool, DuckDuckGoSearchRun # from langchain.tools import BaseTool, DuckDuckGoSearchRun

@ -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.boss.BossNode import BossNodeInitializer as BossNode
from swarms.agents.workers.worker_ultra_node import WorkerUltra 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') 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}") logging.error(f"Failed to initialize vector store: {e}")
return None 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 Init WorkerNode
@ -104,7 +107,7 @@ class Swarms:
# Initialize worker node # Initialize worker node
llm = self.initialize_llm(ChatOpenAI) llm = self.initialize_llm(ChatOpenAI)
worker_node = WorkerNodeInitializer(llm=llm, tools=worker_tools, vectorstore=vectorstore) 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") 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 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_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) 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 = [ 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!"), 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}""" 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 """ 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: except Exception as e:
logging.error(f"An error occured in swarm: {e}") logging.error(f"An error occured in swarm: {e}")
return None return None

Loading…
Cancel
Save