Spaces:
Sleeping
Sleeping
Update pipeline.py
Browse files- pipeline.py +49 -4
pipeline.py
CHANGED
@@ -173,7 +173,52 @@ def do_web_search(query: str) -> str:
|
|
173 |
response = manager_agent.run(search_query)
|
174 |
return response
|
175 |
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
def run_with_chain(query: str) -> str:
|
178 |
print("DEBUG: Starting run_with_chain...")
|
179 |
|
@@ -182,9 +227,8 @@ def run_with_chain(query: str) -> str:
|
|
182 |
if moderated_query == "OutOfScope":
|
183 |
return "Sorry, this query contains harmful or inappropriate content."
|
184 |
|
185 |
-
# Classify the query
|
186 |
-
|
187 |
-
classification = class_result.get("text", "").strip()
|
188 |
print("DEBUG: Classification =>", classification)
|
189 |
|
190 |
if classification == "OutOfScope":
|
@@ -217,3 +261,4 @@ def run_with_chain(query: str) -> str:
|
|
217 |
refusal_text = refusal_chain.run({"topic": "this topic"})
|
218 |
final_refusal = tailor_chain.run({"response": refusal_text})
|
219 |
return final_refusal.strip()
|
|
|
|
173 |
response = manager_agent.run(search_query)
|
174 |
return response
|
175 |
|
176 |
+
|
177 |
+
# # Orchestrator: run_with_chain
|
178 |
+
# def run_with_chain(query: str) -> str:
|
179 |
+
# print("DEBUG: Starting run_with_chain...")
|
180 |
+
|
181 |
+
# # Moderate the query for harmful content
|
182 |
+
# moderated_query = moderate_text(query)
|
183 |
+
# if moderated_query == "OutOfScope":
|
184 |
+
# return "Sorry, this query contains harmful or inappropriate content."
|
185 |
+
|
186 |
+
# # Classify the query
|
187 |
+
# class_result = classification_chain.invoke({"query": moderated_query})
|
188 |
+
# classification = class_result.get("text", "").strip()
|
189 |
+
# print("DEBUG: Classification =>", classification)
|
190 |
+
|
191 |
+
# if classification == "OutOfScope":
|
192 |
+
# refusal_text = refusal_chain.run({"topic": "this topic"})
|
193 |
+
# final_refusal = tailor_chain.run({"response": refusal_text})
|
194 |
+
# return final_refusal.strip()
|
195 |
+
|
196 |
+
# if classification == "Wellness":
|
197 |
+
# rag_result = wellness_rag_chain({"query": moderated_query})
|
198 |
+
# csv_answer = rag_result["result"].strip()
|
199 |
+
# if not csv_answer:
|
200 |
+
# web_answer = do_web_search(moderated_query)
|
201 |
+
# else:
|
202 |
+
# lower_ans = csv_answer.lower()
|
203 |
+
# if any(phrase in lower_ans for phrase in ["i do not know", "not sure", "no context", "cannot answer"]):
|
204 |
+
# web_answer = do_web_search(moderated_query)
|
205 |
+
# else:
|
206 |
+
# web_answer = ""
|
207 |
+
# final_merged = cleaner_chain.merge(kb=csv_answer, web=web_answer)
|
208 |
+
# final_answer = tailor_chain.run({"response": final_merged})
|
209 |
+
# return final_answer.strip()
|
210 |
+
|
211 |
+
# if classification == "Brand":
|
212 |
+
# rag_result = brand_rag_chain({"query": moderated_query})
|
213 |
+
# csv_answer = rag_result["result"].strip()
|
214 |
+
# final_merged = cleaner_chain.merge(kb=csv_answer, web="")
|
215 |
+
# final_answer = tailor_chain.run({"response": final_merged})
|
216 |
+
# return final_answer.strip()
|
217 |
+
|
218 |
+
# refusal_text = refusal_chain.run({"topic": "this topic"})
|
219 |
+
# final_refusal = tailor_chain.run({"response": refusal_text})
|
220 |
+
# return final_refusal.strip()
|
221 |
+
|
222 |
def run_with_chain(query: str) -> str:
|
223 |
print("DEBUG: Starting run_with_chain...")
|
224 |
|
|
|
227 |
if moderated_query == "OutOfScope":
|
228 |
return "Sorry, this query contains harmful or inappropriate content."
|
229 |
|
230 |
+
# Classify the query manually, ensuring box breathing is recognized
|
231 |
+
classification = classify_query(moderated_query)
|
|
|
232 |
print("DEBUG: Classification =>", classification)
|
233 |
|
234 |
if classification == "OutOfScope":
|
|
|
261 |
refusal_text = refusal_chain.run({"topic": "this topic"})
|
262 |
final_refusal = tailor_chain.run({"response": refusal_text})
|
263 |
return final_refusal.strip()
|
264 |
+
|