From 9f9c53bf6a92f7d46083073eed425bc9bac88f7b Mon Sep 17 00:00:00 2001 From: Kye Date: Wed, 5 Jul 2023 17:48:53 -0400 Subject: [PATCH] massive clean up --- swarms/agents/boss/boss_agent.py | 2 +- swarms/agents/workers/worker_agent.py | 3 +- swarms/swarms.py | 2 +- swarms/tools/agent_tools.py | 59 +++++++++++++++++++++++++++ swarms/tools/main.py | 59 --------------------------- 5 files changed, 63 insertions(+), 62 deletions(-) create mode 100644 swarms/tools/agent_tools.py diff --git a/swarms/agents/boss/boss_agent.py b/swarms/agents/boss/boss_agent.py index 6a9d1433..d9e9361d 100644 --- a/swarms/agents/boss/boss_agent.py +++ b/swarms/agents/boss/boss_agent.py @@ -1,4 +1,4 @@ -from swarms.tools.main import * +from swarms.tools.agent_tools import * # ---------- Boss Node ---------- class BossNode: diff --git a/swarms/agents/workers/worker_agent.py b/swarms/agents/workers/worker_agent.py index b8cc7355..4af94eb5 100644 --- a/swarms/agents/workers/worker_agent.py +++ b/swarms/agents/workers/worker_agent.py @@ -1,4 +1,5 @@ -from swarms.tools.main import * +from swarms.tools.agent_tools import * + # ---------- Worker Node ---------- # Define the input schema for the WorkerNode class WorkerNodeInput(BaseModel): diff --git a/swarms/swarms.py b/swarms/swarms.py index 6fe29be6..de779551 100644 --- a/swarms/swarms.py +++ b/swarms/swarms.py @@ -1,4 +1,4 @@ -from swarms.tools.main import * +from swarms.tools.agent_tools import * from swarms.agents.workers.worker_agent import WorkerNode from swarms.agents.boss.boss_agent import BossNode diff --git a/swarms/tools/agent_tools.py b/swarms/tools/agent_tools.py new file mode 100644 index 00000000..c3fb40a7 --- /dev/null +++ b/swarms/tools/agent_tools.py @@ -0,0 +1,59 @@ + + +# ---------- Dependencies ---------- +import os +import asyncio +import faiss +from typing import Any, Optional, List +from contextlib import contextmanager + +from pydantic import BaseModel, Field +from langchain import LLMChain, OpenAI, PromptTemplate +from langchain.chains.base import Chain + +from langchain.experimental import BabyAGI +from langchain.embeddings import OpenAIEmbeddings +from langchain.vectorstores.base import VectorStore +from langchain.vectorstores import FAISS + +from langchain.docstore import InMemoryDocstore +from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain +from langchain.agents import ZeroShotAgent, Tool, AgentExecutor + +from langchain.text_splitter import RecursiveCharacterTextSplitter +from langchain.tools import BaseTool, DuckDuckGoSearchRun +from langchain.tools.file_management.read import ReadFileTool + +from langchain.tools.file_management.write import WriteFileTool +from langchain.tools.human.tool import HumanInputRun +from swarms.tools import Terminal, CodeWriter, CodeEditor, process_csv, WebpageQATool + +from langchain.experimental.autonomous_agents.autogpt.agent import AutoGPT +from langchain.chat_models import ChatOpenAI +from langchain.tools import tool + +# ---------- Constants ---------- +ROOT_DIR = "./data/" + +# ---------- Tools ---------- +openai_api_key = os.environ["OPENAI_API_KEY"] +llm = ChatOpenAI(model_name="gpt-4", temperature=1.0, openai_api_key=openai_api_key) + +tools = [ + DuckDuckGoSearchRun(), + WriteFileTool(root_dir=ROOT_DIR), + ReadFileTool(root_dir=ROOT_DIR), + process_csv, + + WebpageQATool(qa_chain=load_qa_with_sources_chain(llm)), + + # Tool(name='terminal', func=Terminal.execute, description='Operates a terminal'), + # Tool(name='code_writer', func=CodeWriter(), description='Writes code'), + # Tool(name='code_editor', func=CodeEditor(), description='Edits code'),# +] + +# ---------- Vector Store ---------- +embeddings_model = OpenAIEmbeddings() +embedding_size = 1536 +index = faiss.IndexFlatL2(embedding_size) +vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) \ No newline at end of file diff --git a/swarms/tools/main.py b/swarms/tools/main.py index fc993717..491fb31a 100644 --- a/swarms/tools/main.py +++ b/swarms/tools/main.py @@ -2285,62 +2285,3 @@ list_tool.run({}) - - -# ---------- Dependencies ---------- -import os -import asyncio -import faiss -from typing import Any, Optional, List -from contextlib import contextmanager - -from pydantic import BaseModel, Field -from langchain import LLMChain, OpenAI, PromptTemplate -from langchain.chains.base import Chain - -from langchain.experimental import BabyAGI -from langchain.embeddings import OpenAIEmbeddings -from langchain.vectorstores.base import VectorStore -from langchain.vectorstores import FAISS - -from langchain.docstore import InMemoryDocstore -from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain -from langchain.agents import ZeroShotAgent, Tool, AgentExecutor - -from langchain.text_splitter import RecursiveCharacterTextSplitter -from langchain.tools import BaseTool, DuckDuckGoSearchRun -from langchain.tools.file_management.read import ReadFileTool - -from langchain.tools.file_management.write import WriteFileTool -from langchain.tools.human.tool import HumanInputRun -from swarms.tools import Terminal, CodeWriter, CodeEditor, process_csv, WebpageQATool - -from langchain.experimental.autonomous_agents.autogpt.agent import AutoGPT -from langchain.chat_models import ChatOpenAI -from langchain.tools import tool - -# ---------- Constants ---------- -ROOT_DIR = "./data/" - -# ---------- Tools ---------- -openai_api_key = os.environ["OPENAI_API_KEY"] -llm = ChatOpenAI(model_name="gpt-4", temperature=1.0, openai_api_key=openai_api_key) - -tools = [ - DuckDuckGoSearchRun(), - WriteFileTool(root_dir=ROOT_DIR), - ReadFileTool(root_dir=ROOT_DIR), - process_csv, - - WebpageQATool(qa_chain=load_qa_with_sources_chain(llm)), - - # Tool(name='terminal', func=Terminal.execute, description='Operates a terminal'), - # Tool(name='code_writer', func=CodeWriter(), description='Writes code'), - # Tool(name='code_editor', func=CodeEditor(), description='Edits code'),# -] - -# ---------- Vector Store ---------- -embeddings_model = OpenAIEmbeddings() -embedding_size = 1536 -index = faiss.IndexFlatL2(embedding_size) -vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) \ No newline at end of file