Update app.py
Browse files210 unmodified lines2112122132142152162 unmodified lines219220221222223224225226227210 unmodified linesif web_search:search_results = google_search(question)context_str = "\n".join([result["text"] for result in search_results if result["text"]])else:database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)if is_related_to_history(question, conversation_history):2 unmodified linesretriever = database.as_retriever()relevant_docs = retriever.get_relevant_documents(question)context_str = "\n".join([doc.page_content for doc in relevant_docs])prompt_val = ChatPromptTemplate.from_template(prompt)formatted_prompt = prompt_val.format(history=history_str, context=context_str if not web_search else "", question=question)answer = generate_chunked_response(model, formatted_prompt)answer = re.split(r'Question:|Current Question:', answer)[-1].strip()210 unmodified lines2112122132142152162172182192202212222232242252262 unmodified lines229230231232233234235236237238210 unmodified linesif web_search:search_results = google_search(question)context_str = "\n".join([result["text"] for result in search_results if result["text"]])prompt_template = """Answer the question based on the following web search results:Web Search Results:{context}Current Question: {question}Provide a concise and direct answer to the question:"""else:database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)if is_related_to_history(question, conversation_history):2 unmodified linesretriever = database.as_retriever()relevant_docs = retriever.get_relevant_documents(question)context_str = "\n".join([doc.page_content for doc in relevant_docs])prompt_template = prompt # Use the original prompt for document-based answersprompt_val = ChatPromptTemplate.from_template(prompt_template)formatted_prompt = prompt_val.format(history=history_str, context=context_str, question=question)answer = generate_chunked_response(model, formatted_prompt)answer = re.split(r'Question:|Current Question:', answer)[-1].strip()
app.py+13-2