import os
import langchain

from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.text_splitter import CharacterTextSplitter
from langchain import OpenAI, VectorDBQA
from langchain.document_loaders import TextLoader
from langchain.document_loaders import WebBaseLoader

from langchain.agents.agent_toolkits import (
    create_vectorstore_agent,
    VectorStoreToolkit,
    VectorStoreInfo,
)


os.environ['serpapi_api_key']="YOUR_serpapi_api_key"
os.environ['OPENAI_API_KEY']="YOUR_OPENAI_API_KEY"

llm = OpenAI(temperature=0)


loader = TextLoader('the_needed_text.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)

embeddings = OpenAIEmbeddings()
text_store = Chroma.from_documents(texts, embeddings, collection_name="the_needed_text")

loader = WebBaseLoader("https://beta.ruff.rs/docs/faq/")
docs = loader.load()
ruff_texts = text_splitter.split_documents(docs)
ruff_store = Chroma.from_documents(ruff_texts, embeddings, collection_name="ruff")

vectorstore_info = VectorStoreInfo(
    name="the_needed_text_in_detail",
    description="the most recent data of bill gates",
    vectorstore=text_store
)

toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info)


agent_executor = create_vectorstore_agent(
    llm=llm,
    toolkit=toolkit,
    verbose=True
)

agent_executor.run("who is bill gates?, what is his age now? and how many assets he has now? ")
langchain.text_splitter.CharacterTextSplitter langchain.agents.agent_toolkits.VectorStoreToolkit langchain.agents.agent_toolkits.VectorStoreInfo langchain.document_loaders.TextLoader langchain.agents.agent_toolkits.create_vectorstore_agent langchain.document_loaders.WebBaseLoader langchain.vectorstores.Chroma.from_documents langchain.OpenAI langchain.embeddings.openai.OpenAIEmbeddings
[((586, 607), 'langchain.OpenAI', 'OpenAI', ([], {'temperature': '(0)'}), '(temperature=0)\n', (592, 607), False, 'from langchain import OpenAI, VectorDBQA\n'), ((622, 655), 'langchain.document_loaders.TextLoader', 'TextLoader', (['"""the_needed_text.txt"""'], {}), "('the_needed_text.txt')\n", (632, 655), False, 'from langchain.document_loaders import TextLoader\n'), ((700, 755), 'langchain.text_splitter.CharacterTextSplitter', 'CharacterTextSplitter', ([], {'chunk_size': '(1000)', 'chunk_overlap': '(0)'}), '(chunk_size=1000, chunk_overlap=0)\n', (721, 755), False, 'from langchain.text_splitter import CharacterTextSplitter\n'), ((822, 840), 'langchain.embeddings.openai.OpenAIEmbeddings', 'OpenAIEmbeddings', ([], {}), '()\n', (838, 840), False, 'from langchain.embeddings.openai import OpenAIEmbeddings\n'), ((855, 930), 'langchain.vectorstores.Chroma.from_documents', 'Chroma.from_documents', (['texts', 'embeddings'], {'collection_name': '"""the_needed_text"""'}), "(texts, embeddings, collection_name='the_needed_text')\n", (876, 930), False, 'from langchain.vectorstores import Chroma\n'), ((943, 990), 'langchain.document_loaders.WebBaseLoader', 'WebBaseLoader', (['"""https://beta.ruff.rs/docs/faq/"""'], {}), "('https://beta.ruff.rs/docs/faq/')\n", (956, 990), False, 'from langchain.document_loaders import WebBaseLoader\n'), ((1077, 1146), 'langchain.vectorstores.Chroma.from_documents', 'Chroma.from_documents', (['ruff_texts', 'embeddings'], {'collection_name': '"""ruff"""'}), "(ruff_texts, embeddings, collection_name='ruff')\n", (1098, 1146), False, 'from langchain.vectorstores import Chroma\n'), ((1169, 1297), 'langchain.agents.agent_toolkits.VectorStoreInfo', 'VectorStoreInfo', ([], {'name': '"""the_needed_text_in_detail"""', 'description': '"""the most recent data of bill gates"""', 'vectorstore': 'text_store'}), "(name='the_needed_text_in_detail', description=\n    'the most recent data of bill gates', vectorstore=text_store)\n", (1184, 1297), False, 'from langchain.agents.agent_toolkits import create_vectorstore_agent, VectorStoreToolkit, VectorStoreInfo\n'), ((1324, 1377), 'langchain.agents.agent_toolkits.VectorStoreToolkit', 'VectorStoreToolkit', ([], {'vectorstore_info': 'vectorstore_info'}), '(vectorstore_info=vectorstore_info)\n', (1342, 1377), False, 'from langchain.agents.agent_toolkits import create_vectorstore_agent, VectorStoreToolkit, VectorStoreInfo\n'), ((1400, 1464), 'langchain.agents.agent_toolkits.create_vectorstore_agent', 'create_vectorstore_agent', ([], {'llm': 'llm', 'toolkit': 'toolkit', 'verbose': '(True)'}), '(llm=llm, toolkit=toolkit, verbose=True)\n', (1424, 1464), False, 'from langchain.agents.agent_toolkits import create_vectorstore_agent, VectorStoreToolkit, VectorStoreInfo\n')]