worker class clean up

NewTools
Kye 2 years ago
parent 351240078e
commit 04a5151343

@ -6,35 +6,30 @@ from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun, AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun, CallbackManagerForToolRun,
) )
from typing import List, Any from typing import List, Any, Dict
from langchain.memory.chat_message_histories import FileChatMessageHistory from langchain.memory.chat_message_histories import FileChatMessageHistory
import logging import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
class WorkerNodeArgs(BaseModel):
prompt: str
run_manager: Optional[CallbackManagerForToolRun] = None
@tool("WorkerNode") @tool("WorkerNode")
class WorkerNode: class WorkerNode(BaseTool):
"""Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks, it can search the internet or spawn child multi-modality models to process and generate images and text or audio and so on""" """Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks, it can search the internet or spawn child multi-modality models to process and generate images and text or audio and so on"""
# name = "WorkerNode"
# description = "Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks, it can search the internet or spawn child multi-modality models to process and generate images and text or audio and so on"
# llm: ChatOpenAI # add this line
# tools: List[Tool]
# vectorstore: VectorStore
llm: Any
tools: List[Any]
vectorstore: Any
agent: Any = None
def __init__(self, llm: Any, tools: List[Any], vectorstore: Any): args_schema: Optional[Type[BaseModel]] = WorkerNodeArgs
logging.info("Initializing WorkerNode") """Pydantic model class to validate and parse the tool's input arguments."""
super().__init__()
self.llm = llm def __init__(self, **kwargs):
self.tools = tools super().__init__(**kwargs)
self.vectorstore = vectorstore self.llm = kwargs.get('llm')
self.tools = kwargs.get('tools')
self.vectorstore = kwargs.get('vectorstore')
self.agent = None self.agent = None
def create_agent(self, ai_name, ai_role, human_in_the_loop, search_kwargs): def create_agent(self, ai_name, ai_role, human_in_the_loop, search_kwargs):
logging.info("Creating agent in WorkerNode") logging.info("Creating agent in WorkerNode")
self.agent = AutoGPT.from_llm_and_tools( self.agent = AutoGPT.from_llm_and_tools(
@ -48,11 +43,11 @@ class WorkerNode:
) )
self.agent.chain.verbose = True self.agent.chain.verbose = True
# @tool("perform_task")
def _run( def _run(
self, prompt: str, run_manager: Optional[CallbackManagerForToolRun] = None self, tool_input: Dict[str, Any], run_manager: Optional[CallbackManagerForToolRun] = None
) -> str: ) -> str:
"""Use the tool.""" """Use the tool."""
prompt = self._parse_input(tool_input)
tree_of_thoughts_prompt = """ tree_of_thoughts_prompt = """
Imagine three different experts are answering this question. All experts will write down each chain of thought of each step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realises they're wrong at any point then they leave. The question is... Imagine three different experts are answering this question. All experts will write down each chain of thought of each step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realises they're wrong at any point then they leave. The question is...
""" """
@ -68,7 +63,6 @@ class WorkerNode:
# class WorkerNode(BaseTool): # class WorkerNode(BaseTool):
# """Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks, it can search the internet or spawn child multi-modality models to process and generate images and text or audio and so on """ # """Useful for when you need to spawn an autonomous agent instance as a worker to accomplish complex tasks, it can search the internet or spawn child multi-modality models to process and generate images and text or audio and so on """
# name = "WorkerNode" # name = "WorkerNode"

Loading…
Cancel
Save