From ca4452ffe4d5c8908ebbc7873438e772627d51af Mon Sep 17 00:00:00 2001 From: Manu Date: Sat, 8 Jun 2024 10:42:32 +0200 Subject: [PATCH] autogpt --- .../1_babyagi.py | 34 +++++++++++ .../requirements.txt | 1 + .../1_autogpt.py | 59 +++++++++++++++++++ .../French_Revolution_Events.txt | 6 ++ 4 files changed, 100 insertions(+) create mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/1_babyagi.py create mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/requirements.txt create mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/1_autogpt.py create mode 100644 1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/French_Revolution_Events.txt diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/1_babyagi.py b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/1_babyagi.py new file mode 100644 index 0000000..fa9c540 --- /dev/null +++ b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/1_babyagi.py @@ -0,0 +1,34 @@ +from langchain.embeddings import OpenAIEmbeddings +import faiss +from langchain.vectorstores import FAISS +from langchain.docstore import InMemoryDocstore + +# Define the embedding model +embeddings_model = OpenAIEmbeddings(model="text-embedding-ada-002") + +# Initialize the vectorstore +embedding_size = 1536 +index = faiss.IndexFlatL2(embedding_size) +vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) + + + + + + + +from langchain import OpenAI +from langchain_experimental.autonomous_agents import BabyAGI + +# set the goal +goal = "Plan a trip to the Grand Canyon" + +# create thebabyagi agent +# If max_iterations is None, the agent may go on forever if stuck in loops +baby_agi = BabyAGI.from_llm( + llm=OpenAI(model="gpt-3.5-turbo-instruct", temperature=0), + vectorstore=vectorstore, + verbose=False, + max_iterations=3 +) +response = baby_agi({"objective": goal}) \ No newline at end of file diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/requirements.txt b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/requirements.txt new file mode 100644 index 0000000..14955d3 --- /dev/null +++ b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/2 Exploring the Fascinating World of Autonomous Agents: A Closer Look at AutoGPT and BabyAGI/requirements.txt @@ -0,0 +1 @@ +faiss-cpu \ No newline at end of file diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/1_autogpt.py b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/1_autogpt.py new file mode 100644 index 0000000..65ed394 --- /dev/null +++ b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/1_autogpt.py @@ -0,0 +1,59 @@ +from langchain.utilities import GoogleSearchAPIWrapper +from langchain.agents import Tool +from langchain.tools.file_management.write import WriteFileTool +from langchain.tools.file_management.read import ReadFileTool + +#Set up the tools +search = GoogleSearchAPIWrapper() +tools = [ + Tool( + name = "search", + func=search.run, + description="Useful for when you need to answer questions about current events. You should ask targeted questions", + return_direct=True + ), + WriteFileTool(), + ReadFileTool(), +] + + + +# Set up the memory +from langchain.vectorstores import FAISS +from langchain.docstore import InMemoryDocstore +from langchain.embeddings import OpenAIEmbeddings + +embeddings_model = OpenAIEmbeddings(model="text-embedding-ada-002") +embedding_size = 1536 + +import faiss +index = faiss.IndexFlatL2(embedding_size) +vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) + + + + + +# Set up the model and AutoGPT +from langchain_experimental.autonomous_agents import AutoGPT +from langchain.chat_models import ChatOpenAI + +agent = AutoGPT.from_llm_and_tools( + ai_name="Jim", + ai_role="Assistant", + tools=tools, + llm=ChatOpenAI(model="gpt-3.5-turbo", temperature=0), + memory=vectorstore.as_retriever() +) + +# Set verbose to be true +agent.chain.verbose = True + + + + +task = "Provide an analysis of the major historical events that led to the French Revolution" + +agent.run([task]) + + diff --git a/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/French_Revolution_Events.txt b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/French_Revolution_Events.txt new file mode 100644 index 0000000..88f6d78 --- /dev/null +++ b/1 ActiveLoop Courses/1 LangChain & Vector Databases in Production/8 Using Language Model as Reasoning Engines with Agents/3 Using AutoGPT with LangChain/French_Revolution_Events.txt @@ -0,0 +1,6 @@ +1. Lead-in To War: 1763 to 1774 - The Treaty of Paris ends the Seven Years War (French and Indian War) but leaves France in financial crisis. +2. 1789 - France declares war on Austria. +3. April 20, 1792 - France declares war on Austria. +4. April 25, 1792 - First use of the guillotine. +5. June 13, 1792 - Prussia declares war on France. +6. Coup of 18–19 Brumaire - Napoleon Bonaparte seizes power in France, marking the end of the French Revolution and the beginning of the Napoleonic era. \ No newline at end of file