Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,31 +26,31 @@ class Agent1:
|
|
| 26 |
self.model = model
|
| 27 |
|
| 28 |
def rephrase_and_split(self, user_input: str) -> List[str]:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
def process(self, user_input: str) -> Dict[str, List[Dict[str, str]]]:
|
| 56 |
queries = self.rephrase_and_split(user_input)
|
|
|
|
| 26 |
self.model = model
|
| 27 |
|
| 28 |
def rephrase_and_split(self, user_input: str) -> List[str]:
|
| 29 |
+
rephrase_prompt = PromptTemplate(
|
| 30 |
+
input_variables=["query"],
|
| 31 |
+
template="""
|
| 32 |
+
Rephrase the given query into one or more concise, search-engine-friendly formats.
|
| 33 |
+
If the query contains multiple distinct questions, split them.
|
| 34 |
+
Provide ONLY the rephrased queries without any additional text or explanations, one per line.
|
| 35 |
+
|
| 36 |
+
Query: {query}
|
| 37 |
+
|
| 38 |
+
Rephrased queries:"""
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
chain = LLMChain(llm=self.model, prompt=rephrase_prompt)
|
| 42 |
+
response = chain.run(query=user_input).strip()
|
| 43 |
+
|
| 44 |
+
# Split the response at "Rephrased queries:" and take the second part
|
| 45 |
+
split_response = response.split("Rephrased queries:", 1)
|
| 46 |
+
if len(split_response) > 1:
|
| 47 |
+
response = split_response[1].strip()
|
| 48 |
+
|
| 49 |
+
# Remove any lines that contain instructions or explanations
|
| 50 |
+
rephrased_queries = [q.strip() for q in response.split('\n') if q.strip() and not q.startswith("Rephrase") and "query" not in q.lower()]
|
| 51 |
+
|
| 52 |
+
# If no valid rephrased queries, return the original input
|
| 53 |
+
return rephrased_queries if rephrased_queries else [user_input]
|
| 54 |
|
| 55 |
def process(self, user_input: str) -> Dict[str, List[Dict[str, str]]]:
|
| 56 |
queries = self.rephrase_and_split(user_input)
|