Shreyas094
commited on
Commit
•
65a5885
1
Parent(s):
76a1b1e
Update app.py
Browse files
app.py
CHANGED
@@ -240,7 +240,7 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
240 |
# Convert web search results to Document format
|
241 |
web_docs = [Document(page_content=result["text"], metadata={"source": result["link"]}) for result in search_results if result["text"]]
|
242 |
|
243 |
-
#
|
244 |
if os.path.exists("faiss_database"):
|
245 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
246 |
database.add_documents(web_docs)
|
@@ -259,7 +259,12 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
259 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
260 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
261 |
else:
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
263 |
history_str = "\n".join([f"Q: {item['question']}\nA: {item['answer']}" for item in conversation_history])
|
264 |
|
265 |
if is_related_to_history(question, conversation_history):
|
|
|
240 |
# Convert web search results to Document format
|
241 |
web_docs = [Document(page_content=result["text"], metadata={"source": result["link"]}) for result in search_results if result["text"]]
|
242 |
|
243 |
+
# Check if the FAISS database exists
|
244 |
if os.path.exists("faiss_database"):
|
245 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
246 |
database.add_documents(web_docs)
|
|
|
259 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
260 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
261 |
else:
|
262 |
+
# Check if the FAISS database exists
|
263 |
+
if os.path.exists("faiss_database"):
|
264 |
+
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
265 |
+
else:
|
266 |
+
return "No FAISS database found. Please upload documents to create the vector store."
|
267 |
+
|
268 |
history_str = "\n".join([f"Q: {item['question']}\nA: {item['answer']}" for item in conversation_history])
|
269 |
|
270 |
if is_related_to_history(question, conversation_history):
|