Spaces:
Running
Running
Update pipeline.py
Browse files- pipeline.py +4 -4
pipeline.py
CHANGED
@@ -178,15 +178,15 @@ def build_rag_chain(llm_model: LiteLLMModel, vectorstore: FAISS) -> RetrievalQA:
|
|
178 |
def run_pipeline(query: str) -> str:
|
179 |
try:
|
180 |
query = sanitize_message(query)
|
181 |
-
|
182 |
moderation_result = moderate_text(query)
|
183 |
if not moderation_result.is_safe:
|
184 |
return "Sorry, this query contains harmful or inappropriate content."
|
185 |
|
186 |
classification = classify_query(moderation_result.original_text)
|
187 |
-
|
188 |
if classification == "OutOfScope":
|
189 |
-
refusal_text = refusal_chain.run({"topic":
|
190 |
return tailor_chain.run({"response": refusal_text}).strip()
|
191 |
|
192 |
if classification == "Wellness":
|
@@ -201,7 +201,7 @@ def run_pipeline(query: str) -> str:
|
|
201 |
csv_answer = rag_result["result"].strip()
|
202 |
final_merged = merge_responses(csv_answer, "")
|
203 |
return tailor_chain.run({"response": final_merged}).strip()
|
204 |
-
|
205 |
refusal_text = refusal_chain.run({"topic": "this topic"})
|
206 |
return tailor_chain.run({"response": refusal_text}).strip()
|
207 |
except Exception as e:
|
|
|
178 |
def run_pipeline(query: str) -> str:
|
179 |
try:
|
180 |
query = sanitize_message(query)
|
181 |
+
topic=extract_main_topic(query)
|
182 |
moderation_result = moderate_text(query)
|
183 |
if not moderation_result.is_safe:
|
184 |
return "Sorry, this query contains harmful or inappropriate content."
|
185 |
|
186 |
classification = classify_query(moderation_result.original_text)
|
187 |
+
|
188 |
if classification == "OutOfScope":
|
189 |
+
refusal_text = refusal_chain.run({"topic": topic})
|
190 |
return tailor_chain.run({"response": refusal_text}).strip()
|
191 |
|
192 |
if classification == "Wellness":
|
|
|
201 |
csv_answer = rag_result["result"].strip()
|
202 |
final_merged = merge_responses(csv_answer, "")
|
203 |
return tailor_chain.run({"response": final_merged}).strip()
|
204 |
+
|
205 |
refusal_text = refusal_chain.run({"topic": "this topic"})
|
206 |
return tailor_chain.run({"response": refusal_text}).strip()
|
207 |
except Exception as e:
|