Update app.py
Browse files628 unmodified lines62963063163263363463563663763863913 unmodified lines653654655656657658659660628 unmodified linesinput_variables=["query"],template="""Rephrase the following conversational query into a concise, search-engine-friendly format.Remove any conversational elements and focus on the core information need.Provide ONLY the rephrased query without any explanation or additional text.Conversational query: {query}Rephrased query:""")13 unmodified lines# Check if the rephrased query is actually a rephrasing and not the original prompt or instructionsif (rephrased_query.lower().startswith(("rephrase", "your task")) orlen(rephrased_query.split()) > len(query.split()) * 2):# If it's not a proper rephrasing, use a simple keyword extractionkeywords = ' '.join(word for word in query.lower().split() if word not in {'how', 'did', 'the', 'in', 'a', 'an', 'and', 'or', 'but', 'is', 'are', 'was', 'were'})return keywordsreturn rephrased_query628 unmodified lines62963063163263363463563663763863913 unmodified lines653654655656657658659660661662663664665666667668628 unmodified linesinput_variables=["query"],template="""Rephrase the following conversational query into a concise, search-engine-friendly format.Maintain key terms and add relevant context if necessary.Provide ONLY the rephrased query without any explanation or additional text.Conversational query: {query}Rephrased query:""")13 unmodified lines# Check if the rephrased query is actually a rephrasing and not the original prompt or instructionsif (rephrased_query.lower().startswith(("rephrase", "your task")) orlen(rephrased_query.split()) > len(query.split()) * 2):# If it's not a proper rephrasing, use a more sophisticated keyword extractionkeywords = query.lower()# Remove common stop words and question wordsstop_words = {'how', 'did', 'the', 'in', 'a', 'an', 'and', 'or', 'but', 'is', 'are', 'was', 'were', 'perform'}keywords = ' '.join(word for word in keywords.split() if word not in stop_words)# Ensure important terms are includedif 'kkr' not in keywords:keywords = 'kkr ' + keywordsif 'q1 2024' not in keywords:keywords += ' q1 2024'return keywordsreturn rephrased_query
app.py+13-5