Find answers from the community

Home
Members
Ataliba Miguel
A
Ataliba Miguel
Offline, last seen 3 months ago
Joined September 25, 2024
Hi All, I need help as I am really struggling to get it to work streamlit file_uploader with llamaIndex. def configure_qa_chain(uploaded_files):
docs = []
with tempfile.TemporaryDirectory() as temp_dir:
for file in uploaded_files:
with tempfile.NamedTemporaryFile(delete=False, dir=temp_dir) as tmp_file:
tmp_file.write(file.getvalue())
tmp_file_path = tmp_file.name
docs.append(tmp_file_path)
loader = PyPDFLoader(file_path=tmp_file_path)
docs = loader.load()
nodes = SimpleNodeParser(text_splitter=" ") .get_nodes_from_documents([docs])
MONGO_URI = os.environ["MONGO_URI"]
MONGODB_DATABASE = "LlamaIndex_Chat"
docstore = MongoDocumentStore.from_uri(uri=MONGO_URI)
docstore.add_documents(nodes)
storage_context = StorageContext.from_defaults(docstore=MongoDocumentStore.from_uri(uri=MONGO_URI, db_name=MONGODB_DATABASE),
index_store=MongoIndexStore.from_uri(uri=MONGO_URI, db_name=MONGODB_DATABASE),)
docstore = MongoDocumentStore.from_uri(uri=MONGO_URI, db_name=MONGODB_DATABASE)
nodes = list(docstore.docs.values())
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
llm = ChatOpenAI( model_name="gpt-3.5-turbo", temperature=0, openai_api_key=openai.api_key,
streaming=True)
llm_predictor = LLMPredictor(llm=llm)
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
list_index = GPTListIndex(nodes, storage_context=storage_context, service_context=service_context)
vector_index = GPTVectorStoreIndex(nodes, storage_context=storage_context, service_context=service_context)
keyword_table_index = GPTSimpleKeywordTableIndex(nodes, storage_context=storage_context, service_context=service_context)
vector_response = vector_index.as_query_engine().query(user_query)
return vector_response
35 comments
A
L
E
Hey'll,

I am really struggling here, does anyone could provide support in guiding me on how/where to find the info under the mongoDB account? Some screenshots on how/where to find the required info for: (It is related to mongodb loader)

host = ?????
port = ?????

db_name = MONGODB_DATABASE
collection_name = ???? # is this the same name for collections? "Collections"

query_dict is passed into db.collection.find()

query_dict = {}

reader = SimpleMongoReader(host, port)

documents = reader.load_data(
db_name, collection_name, query_dict=query_dict)
27 comments
V
A
c