devve1 commited on
Commit
b1136c7
1 Parent(s): 507ceb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -99,7 +99,7 @@ def rrf(rank_lists, alpha=60, default_rank=1000):
99
  return sorted_items
100
 
101
 
102
- def main(query: str, client: QdrantClient, collection_name: str, llm, dense_model, sparse_model):
103
  dense_query = list(dense_model.embed_query(query, 32))
104
  sparse_query = list(sparse_model.embed(query, 32))
105
 
@@ -358,7 +358,7 @@ def chunk_documents(texts, metadatas, dense_model, sparse_model):
358
 
359
  return documents, metadatas_docs, dense_embeddings, sparse_embeddings
360
 
361
- def on_change_documents_only(qa_prompt):
362
  qa_prompt = lambda query, context: (
363
  f"""You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise.
364
 
@@ -374,7 +374,9 @@ def on_change_documents_only(qa_prompt):
374
  {context}
375
 
376
  Question: {query}"""
377
- )
 
 
378
 
379
 
380
  if __name__ == '__main__':
@@ -398,7 +400,7 @@ if __name__ == '__main__':
398
  st.chat_message("user").markdown(prompt)
399
  st.session_state.messages.append({"role": "user", "content": prompt})
400
 
401
- ai_response, ai_response_with_metadatas = main(prompt, client, collection_name, llm, dense_model, sparse_model, IsDocumentsOnly)
402
  with st.chat_message("assistant"):
403
  message_placeholder = st.empty()
404
  full_response = ""
@@ -466,15 +468,13 @@ if __name__ == '__main__':
466
  )
467
  st.sidebar.success("Document content uploaded and ready!")
468
 
 
 
469
  IsDocumentsOnly = st.sidebar.toggle(
470
  label="""Enable 'Documents-Only' Mode""",
471
  value=True,
472
  on_change=on_change_documents_only,
473
  key="documents_only",
474
- args=(qa_prompt, )
475
- )
476
-
477
- if IsDocumentsOnly:
478
- st.sidebar.write('The AI answer your questions only considering the documents provided')
479
- else:
480
- st.sidebar.write("""The AI answer your questions considering the documents provided, and if it doesn't found the answer in them, try to find in its on own internal knowledge""")
 
99
  return sorted_items
100
 
101
 
102
+ def main(query: str, client: QdrantClient, collection_name: str, llm, dense_model, sparse_model, qa_prompt):
103
  dense_query = list(dense_model.embed_query(query, 32))
104
  sparse_query = list(sparse_model.embed(query, 32))
105
 
 
358
 
359
  return documents, metadatas_docs, dense_embeddings, sparse_embeddings
360
 
361
+ def on_change_documents_only(qa_prompt, tooltip):
362
  qa_prompt = lambda query, context: (
363
  f"""You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise.
364
 
 
374
  {context}
375
 
376
  Question: {query}"""
377
+ )
378
+
379
+ tooltip = 'The AI answer your questions only considering the documents provided' if st.session_state.documents_only else """The AI answer your questions considering the documents provided, and if it doesn't found the answer in them, try to find in its on own internal knowledge"""
380
 
381
 
382
  if __name__ == '__main__':
 
400
  st.chat_message("user").markdown(prompt)
401
  st.session_state.messages.append({"role": "user", "content": prompt})
402
 
403
+ ai_response, ai_response_with_metadatas = main(prompt, client, collection_name, llm, dense_model, sparse_model, qa_prompt)
404
  with st.chat_message("assistant"):
405
  message_placeholder = st.empty()
406
  full_response = ""
 
468
  )
469
  st.sidebar.success("Document content uploaded and ready!")
470
 
471
+ tooltip = 'The AI answer your questions only considering the documents provided'
472
+
473
  IsDocumentsOnly = st.sidebar.toggle(
474
  label="""Enable 'Documents-Only' Mode""",
475
  value=True,
476
  on_change=on_change_documents_only,
477
  key="documents_only",
478
+ args=(qa_prompt, tooltip),
479
+ help=tooltip
480
+ )