Created
October 26, 2023 06:31
-
-
Save codegod100/6143a6e6e26e6314f7f1ede4189018bc to your computer and use it in GitHub Desktop.
document look using agent
This file contains hidden or 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.document_loaders import TextLoader | |
| from langchain.embeddings.openai import OpenAIEmbeddings | |
| from langchain.text_splitter import CharacterTextSplitter | |
| from langchain.vectorstores import FAISS | |
| from langchain.document_loaders import UnstructuredMarkdownLoader | |
| from langchain.document_loaders import DirectoryLoader | |
| from langchain.chat_models.fireworks import ChatFireworks | |
| from langchain.agents.agent_toolkits import ( | |
| create_vectorstore_agent, | |
| VectorStoreToolkit, | |
| VectorStoreInfo, | |
| ) | |
| llm = ChatFireworks(model="accounts/fireworks/models/mistral-7b") | |
| path = "/home/vera/agora/garden/journal" | |
| loader = DirectoryLoader(path, glob="**/*.md") | |
| data = loader.load() | |
| text_splitter = CharacterTextSplitter(chunk_size=200, chunk_overlap=0) | |
| documents = text_splitter.split_documents(data) | |
| db = FAISS.from_documents(documents, OpenAIEmbeddings()) | |
| vectorstore_info = VectorStoreInfo( | |
| name="vera's journal", | |
| description="collection of markdown files containing vera's daily journal", | |
| vectorstore=db, | |
| ) | |
| query = "What does vera enjoy doing?" | |
| toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info) | |
| agent_executor = create_vectorstore_agent(llm=llm, toolkit=toolkit, verbose=True) | |
| resp = agent_executor.run(query) | |
| print(resp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment