Shreyas094 commited on
Commit
8491a9e
1 Parent(s): 7945e18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
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
- 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)
 
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)