Update pipeline.py
Browse files- pipeline.py +9 -11
pipeline.py
CHANGED
@@ -148,22 +148,21 @@ def run_with_chain_context(inputs: Dict[str, Any]) -> Dict[str, str]:
|
|
148 |
return {"answer": final_refusal.strip()}
|
149 |
|
150 |
if classification == "Wellness":
|
151 |
-
rag_result = wellness_rag_chain.invoke({
|
|
|
|
|
|
|
152 |
csv_answer = rag_result["result"].strip()
|
153 |
-
if not csv_answer
|
154 |
-
web_answer = do_web_search(user_query)
|
155 |
-
else:
|
156 |
-
lower_ans = csv_answer.lower()
|
157 |
-
if any(phrase in lower_ans for phrase in ["i do not know", "not sure", "no context", "cannot answer"]):
|
158 |
-
web_answer = do_web_search(user_query)
|
159 |
-
else:
|
160 |
-
web_answer = ""
|
161 |
final_merged = cleaner_chain.merge(kb=csv_answer, web=web_answer)
|
162 |
final_answer = tailor_chain.run({"response": final_merged}).strip()
|
163 |
return {"answer": final_answer}
|
164 |
|
165 |
if classification == "Brand":
|
166 |
-
rag_result = brand_rag_chain.invoke({
|
|
|
|
|
|
|
167 |
csv_answer = rag_result["result"].strip()
|
168 |
final_merged = cleaner_chain.merge(kb=csv_answer, web="")
|
169 |
final_answer = tailor_chain.run({"response": final_merged}).strip()
|
@@ -172,7 +171,6 @@ def run_with_chain_context(inputs: Dict[str, Any]) -> Dict[str, str]:
|
|
172 |
refusal_text = refusal_chain.run({})
|
173 |
final_refusal = tailor_chain.run({"response": refusal_text}).strip()
|
174 |
return {"answer": final_refusal}
|
175 |
-
|
176 |
###############################################################################
|
177 |
# 7) Build a "Runnable" wrapper so .with_listeners() works
|
178 |
###############################################################################
|
|
|
148 |
return {"answer": final_refusal.strip()}
|
149 |
|
150 |
if classification == "Wellness":
|
151 |
+
rag_result = wellness_rag_chain.invoke({
|
152 |
+
"query": user_query,
|
153 |
+
"chat_history": chat_history # Pass history here
|
154 |
+
})
|
155 |
csv_answer = rag_result["result"].strip()
|
156 |
+
web_answer = do_web_search(user_query) if not csv_answer else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
final_merged = cleaner_chain.merge(kb=csv_answer, web=web_answer)
|
158 |
final_answer = tailor_chain.run({"response": final_merged}).strip()
|
159 |
return {"answer": final_answer}
|
160 |
|
161 |
if classification == "Brand":
|
162 |
+
rag_result = brand_rag_chain.invoke({
|
163 |
+
"query": user_query,
|
164 |
+
"chat_history": chat_history # Pass history here
|
165 |
+
})
|
166 |
csv_answer = rag_result["result"].strip()
|
167 |
final_merged = cleaner_chain.merge(kb=csv_answer, web="")
|
168 |
final_answer = tailor_chain.run({"response": final_merged}).strip()
|
|
|
171 |
refusal_text = refusal_chain.run({})
|
172 |
final_refusal = tailor_chain.run({"response": refusal_text}).strip()
|
173 |
return {"answer": final_refusal}
|
|
|
174 |
###############################################################################
|
175 |
# 7) Build a "Runnable" wrapper so .with_listeners() works
|
176 |
###############################################################################
|