Update app.py
Browse files628 unmodified lines62963063163263263363463463563663663763863913 unmodified lines653654655656657656657658659660661662663664665666667668628 unmodified lines input_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. 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 instructions if (rephrased_query.lower().startswith(("rephrase", "your task")) or len(rephrased_query.split()) > len(query.split()) * 2): # If it's not a proper rephrasing, use a simple keyword extraction keywords = ' '.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'}) # If it's not a proper rephrasing, use a more sophisticated keyword extraction keywords = query.lower() # Remove common stop words and question words stop_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 included if 'kkr' not in keywords: keywords = 'kkr ' + keywords if 'q1 2024' not in keywords: keywords += ' q1 2024' return keywords return rephrased_queryapp.py+13-5