Update app.py
Browse files230 unmodified lines2312322332342352362372382392405 unmodified lines246247248249250251252230 unmodified linesanswer = memory_database[question]else:model = get_model(temperature, top_p, repetition_penalty)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:5 unmodified linesprompt_val = ChatPromptTemplate.from_template(prompt_template)formatted_prompt = prompt_val.format(context=context_str, question=question)else:embed = get_embeddings()database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)history_str = "\n".join([f"Q: {item['question']}\nA: {item['answer']}" for item in conversation_history])230 unmodified lines2312322332342352362372382392402412422432442452462472482492502512522535 unmodified lines259260261262263264230 unmodified linesanswer = memory_database[question]else:model = get_model(temperature, top_p, repetition_penalty)embed = get_embeddings()if web_search:search_results = google_search(question)context_str = "\n".join([result["text"] for result in search_results if result["text"]])# Convert web search results to Document formatweb_docs = [Document(page_content=result["text"], metadata={"source": result["link"]}) for result in search_results if result["text"]]# Load or create the vector databaseif os.path.exists("faiss_database"):database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)database.add_documents(web_docs)else:database = FAISS.from_documents(web_docs, embed)database.save_local("faiss_database")prompt_template = """Answer the question based on the following web search results:Web Search Results:5 unmodified linesprompt_val = ChatPromptTemplate.from_template(prompt_template)formatted_prompt = prompt_val.format(context=context_str, question=question)else:database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)history_str = "\n".join([f"Q: {item['question']}\nA: {item['answer']}" for item in conversation_history])
app.py+13-1