|
|
|
@ -71,7 +71,9 @@ from swarms.tools.main import Terminal, CodeWriter, CodeEditor, process_csv, Web
|
|
|
|
|
from swarms.tools.main import math_tool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
llm = ChatOpenAI(model_name="gpt-4", temperature=1.0, openai_api_key="")
|
|
|
|
|
openai_api_key = os.environ["OPENAI_API_KEY"]
|
|
|
|
|
|
|
|
|
|
llm = ChatOpenAI(model_name="gpt-4", temperature=1.0, openai_api_key=openai_api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####################### TOOLS
|
|
|
|
@ -157,14 +159,14 @@ class WorkerNode:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# #inti worker node with llm
|
|
|
|
|
# worker_node = WorkerNode(llm=llm, tools=tools, vectorstore=vectorstore)
|
|
|
|
|
#inti worker node with llm
|
|
|
|
|
worker_node = WorkerNode(llm=llm, tools=tools, vectorstore=vectorstore)
|
|
|
|
|
|
|
|
|
|
# #create an agent within the worker node
|
|
|
|
|
# worker_node.create_agent(ai_name="AI Assistant", ai_role="Assistant", human_in_the_loop=True, search_kwargs={})
|
|
|
|
|
#create an agent within the worker node
|
|
|
|
|
worker_node.create_agent(ai_name="AI Assistant", ai_role="Assistant", human_in_the_loop=True, search_kwargs={})
|
|
|
|
|
|
|
|
|
|
# #use the agent to perform a task
|
|
|
|
|
# worker_node.run_agent("Find 20 potential customers for a Swarms based AI Agent automation infrastructure")
|
|
|
|
|
#use the agent to perform a task
|
|
|
|
|
worker_node.run_agent("Find 20 potential customers for a Swarms based AI Agent automation infrastructure")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#======================================> WorkerNode
|
|
|
|
@ -272,8 +274,28 @@ meta_worker_node.main(task)
|
|
|
|
|
####################################################################### => Boss Node
|
|
|
|
|
|
|
|
|
|
class BossNode:
|
|
|
|
|
def __init__(self, llm, vectorstore, task_execution_chain, verbose, max_iterations):
|
|
|
|
|
def __init__(self, openai_api_key, llm, vectorstore, task_execution_chain, verbose, max_iterations):
|
|
|
|
|
self.llm = llm
|
|
|
|
|
self.openai_api_key = openai_api_key
|
|
|
|
|
self.vectorstore = vectorstore
|
|
|
|
|
self.task_execution_chain = task_execution_chain
|
|
|
|
|
self.verbose = verbose
|
|
|
|
|
self.max_iterations = max_iterations
|
|
|
|
|
|
|
|
|
|
self.baby_agi = BabyAGI.from_llm(
|
|
|
|
|
llm=self.llm,
|
|
|
|
|
vectorstore=self.vectorstore,
|
|
|
|
|
task_execution_chain=self.task_execution_chain
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def create_task(self, objective):
|
|
|
|
|
return {"objective": objective}
|
|
|
|
|
|
|
|
|
|
def execute_task(self, task):
|
|
|
|
|
self.baby_agi(task)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
########### ===============> inputs to boss None
|
|
|
|
|
todo_prompt = PromptTemplate.from_template(
|
|
|
|
|
"You are a planner who is an expert at coming up with a todo list for a given objective. Come up with a todo list for this objective: {objective}"""
|
|
|
|
|
)
|
|
|
|
@ -333,20 +355,14 @@ class BossNode:
|
|
|
|
|
agent_executor = AgentExecutor.from_agent_and_tools(
|
|
|
|
|
agent=agent, tools=tools, verbose=True
|
|
|
|
|
)
|
|
|
|
|
self.baby_agi = BabyAGI.from_llm(
|
|
|
|
|
llm=llm,
|
|
|
|
|
vectorstore=vectorstore,
|
|
|
|
|
task_execution_chain=agent_executor
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def create_task(self, objective):
|
|
|
|
|
return {"objective": objective}
|
|
|
|
|
|
|
|
|
|
def execute_task(self, task):
|
|
|
|
|
self.baby_agi(task)
|
|
|
|
|
|
|
|
|
|
boss_node = BossNode(llm=llm, vectorstore=vectorstore, task_execution_chain=agent_executor, verbose=True, max_iterations=5)
|
|
|
|
|
|
|
|
|
|
#create a task
|
|
|
|
|
task = boss_node.create_task(objective="Write a research paper on the impact of climate change on global agriculture")
|
|
|
|
|
|
|
|
|
|
#execute the task
|
|
|
|
|
boss_node.execute_task(task)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Swarms:
|
|
|
|
|