Created
April 25, 2023 02:09
-
-
Save auguststurm/ffca78bfc4a6ad5e0777811fb361d6d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
from dotenv import load_dotenv | |
import os | |
load_dotenv() | |
os.environ["GOOGLE_CSE_ID"] = os.getenv("GOOGLE_CSE_ID") | |
os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY") | |
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY") | |
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." | |
), | |
WriteFileTool(), | |
ReadFileTool() | |
] | |
from langchain.vectorstores import FAISS | |
from langchain.docstore import InMemoryDocstore | |
from langchain.embeddings import OpenAIEmbeddings | |
# Define your embedding model | |
embeddings_model = OpenAIEmbeddings() | |
# Initialize the vector store as empty | |
import faiss | |
embedding_size = 1536 | |
index = faiss.IndexFlatL2(embedding_size) | |
vectorstore = FAISS(embeddings_model.embed_query, index, InMemoryDocstore({}), {}) | |
from langchain.experimental import AutoGPT | |
from langchain.chat_models import ChatOpenAI | |
agent = AutoGPT.from_llm_and_tools( | |
ai_name="Gus", | |
ai_role="Research Agent", | |
tools=tools, | |
llm=ChatOpenAI(temperature=0.618), | |
memory=vectorstore.as_retriever() | |
) | |
# Set verbose to be true | |
agent.chain.verbose = True | |
agent.run(["Write a textbook example of the Abstract Factory Pattern in Typescript utilizing types, interfaces, and classes."]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment