Update app.py
Browse files43 unmodified lines444546474849505152535445 unmodified lines1001011021031041053 unmodified lines109110111112113114115116117118119120121122123124125126127128129130178 unmodified lines30931031131231331443 unmodified linesnlp = load_spacy_model()class EnhancedContextDrivenChatbot:def __init__(self, history_size=10):self.history = []self.history_size = history_sizeself.entity_tracker = {}self.conversation_context = ""def add_to_history(self, text):self.history.append(text)45 unmodified linesreturn questiondef rephrase_query(self, question):prompt = f"""Given the conversation context and the current question, rephrase the question to include relevant context:3 unmodified linesRephrased question:"""# Use your language model to generate the rephrased questionrephrased_question = generate_chunked_response(model, prompt)return rephrased_question.strip()def process_question(self, question):contextualized_question = self.get_most_relevant_context(question)# Extract topics from the questiontopics = self.extract_topics(question)# Check if it's a follow-up question and rephrase if necessaryif self.is_follow_up_question(question):contextualized_question = self.rephrase_query(contextualized_question)# Add the new question to historyself.add_to_history(question)return contextualized_question, topics, self.entity_tracker178 unmodified linesreturn "Please enter a question."model = get_model(temperature, top_p, repetition_penalty)embed = get_embeddings()if os.path.exists("faiss_database"):43 unmodified lines44454647484950515253545545 unmodified lines1011021031041051061071081093 unmodified lines113114115116117118119120121122123124125126127128129130178 unmodified lines30931031131231331431531631731843 unmodified linesnlp = load_spacy_model()class EnhancedContextDrivenChatbot:def __init__(self, history_size=10, model=None):self.history = []self.history_size = history_sizeself.entity_tracker = {}self.conversation_context = ""self.model = modeldef add_to_history(self, text):self.history.append(text)45 unmodified linesreturn questiondef rephrase_query(self, question):if not self.model:return question # Return original question if no model is availableprompt = f"""Given the conversation context and the current question, rephrase the question to include relevant context:3 unmodified linesRephrased question:"""rephrased_question = generate_chunked_response(self.model, prompt)return rephrased_question.strip()def process_question(self, question):contextualized_question = self.get_most_relevant_context(question)topics = self.extract_topics(question)if self.is_follow_up_question(question):contextualized_question = self.rephrase_query(contextualized_question)self.add_to_history(question)return contextualized_question, topics, self.entity_tracker178 unmodified linesreturn "Please enter a question."model = get_model(temperature, top_p, repetition_penalty)# Update the chatbot's modelchatbot.model = modelembed = get_embeddings()if os.path.exists("faiss_database"):
app.py+10-6