Skip to content

Commit

Permalink
autogpt
Browse files Browse the repository at this point in the history
  • Loading branch information
manufy committed Jun 8, 2024
1 parent 3afe2e5 commit ca4452f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
faiss-cpu
Original file line number Diff line number Diff line change
@@ -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])


Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit ca4452f

Please sign in to comment.