Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -630,23 +630,26 @@ def rephrase_for_search(query, model):
|
|
| 630 |
template="""
|
| 631 |
Your task is to rephrase the given conversational query into a concise, search-engine-friendly format.
|
| 632 |
Remove any conversational elements and focus on the core information need.
|
|
|
|
| 633 |
|
| 634 |
Conversational query: {query}
|
| 635 |
|
| 636 |
-
Rephrased query:
|
| 637 |
)
|
| 638 |
|
| 639 |
chain = LLMChain(llm=model, prompt=rephrase_prompt)
|
| 640 |
response = chain.run(query=query).strip()
|
| 641 |
|
| 642 |
-
#
|
| 643 |
-
rephrased_query = response.
|
| 644 |
|
| 645 |
-
#
|
| 646 |
-
if rephrased_query.lower().
|
| 647 |
-
#
|
| 648 |
-
|
| 649 |
-
|
|
|
|
|
|
|
| 650 |
|
| 651 |
return rephrased_query
|
| 652 |
|
|
|
|
| 630 |
template="""
|
| 631 |
Your task is to rephrase the given 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 additional text or explanations.
|
| 634 |
|
| 635 |
Conversational query: {query}
|
| 636 |
|
| 637 |
+
Rephrased query:"""
|
| 638 |
)
|
| 639 |
|
| 640 |
chain = LLMChain(llm=model, prompt=rephrase_prompt)
|
| 641 |
response = chain.run(query=query).strip()
|
| 642 |
|
| 643 |
+
# Remove any potential "Rephrased query:" prefix
|
| 644 |
+
rephrased_query = response.replace("Rephrased query:", "").strip()
|
| 645 |
|
| 646 |
+
# If the rephrased query is too similar to the original, extract keywords
|
| 647 |
+
if rephrased_query.lower() == query.lower() or len(rephrased_query) > len(query) * 1.5:
|
| 648 |
+
# Simple keyword extraction: remove common words and punctuation
|
| 649 |
+
common_words = set(['the', 'a', 'an', 'in', 'on', 'at', 'to', 'for', 'of', 'with', 'by', 'from', 'up', 'about', 'into', 'over', 'after'])
|
| 650 |
+
keywords = [word.lower() for word in query.split() if word.lower() not in common_words]
|
| 651 |
+
keywords = [word for word in keywords if word.isalnum()]
|
| 652 |
+
return ' '.join(keywords)
|
| 653 |
|
| 654 |
return rephrased_query
|
| 655 |
|