Shreyas094 commited on
Commit
8ac5745
·
verified ·
1 Parent(s): d16acd0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -629,11 +629,11 @@ def rephrase_for_search(query, model):
629
  input_variables=["query"],
630
  template="""
631
  Rephrase the following conversational query into a concise, search-engine-friendly format.
632
- Remove any conversational elements and focus on the core information need.
633
  Provide ONLY the rephrased query without any explanation or additional text.
634
-
635
  Conversational query: {query}
636
-
637
  Rephrased query:"""
638
  )
639
 
@@ -653,8 +653,16 @@ def rephrase_for_search(query, model):
653
  # Check if the rephrased query is actually a rephrasing and not the original prompt or instructions
654
  if (rephrased_query.lower().startswith(("rephrase", "your task")) or
655
  len(rephrased_query.split()) > len(query.split()) * 2):
656
- # If it's not a proper rephrasing, use a simple keyword extraction
657
- 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'})
 
 
 
 
 
 
 
 
658
  return keywords
659
 
660
  return rephrased_query
 
629
  input_variables=["query"],
630
  template="""
631
  Rephrase the following conversational query into a concise, search-engine-friendly format.
632
+ Maintain key terms and add relevant context if necessary.
633
  Provide ONLY the rephrased query without any explanation or additional text.
634
+
635
  Conversational query: {query}
636
+
637
  Rephrased query:"""
638
  )
639
 
 
653
  # Check if the rephrased query is actually a rephrasing and not the original prompt or instructions
654
  if (rephrased_query.lower().startswith(("rephrase", "your task")) or
655
  len(rephrased_query.split()) > len(query.split()) * 2):
656
+ # If it's not a proper rephrasing, use a more sophisticated keyword extraction
657
+ keywords = query.lower()
658
+ # Remove common stop words and question words
659
+ stop_words = {'how', 'did', 'the', 'in', 'a', 'an', 'and', 'or', 'but', 'is', 'are', 'was', 'were', 'perform'}
660
+ keywords = ' '.join(word for word in keywords.split() if word not in stop_words)
661
+ # Ensure important terms are included
662
+ if 'kkr' not in keywords:
663
+ keywords = 'kkr ' + keywords
664
+ if 'q1 2024' not in keywords:
665
+ keywords += ' q1 2024'
666
  return keywords
667
 
668
  return rephrased_query