Update app.py
Browse files210 unmodified lines2112122132142152162172182192202212222232242252262 unmodified lines229230231232233223224234235236237238210 unmodified lines if 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 lines retriever = 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 answers prompt_val = ChatPromptTemplate.from_template(prompt) formatted_prompt = prompt_val.format(history=history_str, context=context_str if not web_search else "", question=question) prompt_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