Spaces:
Sleeping
Sleeping
Update chatbot_rag.py
Browse files- chatbot_rag.py +14 -0
chatbot_rag.py
CHANGED
|
@@ -95,3 +95,17 @@ except Exception as e:
|
|
| 95 |
print("❌ Failed to build QA pipeline")
|
| 96 |
print("Error message:", str(e))
|
| 97 |
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
print("❌ Failed to build QA pipeline")
|
| 96 |
print("Error message:", str(e))
|
| 97 |
traceback.print_exc()
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def get_answer(query: str) -> str:
|
| 101 |
+
"""
|
| 102 |
+
Run a query against the QA pipeline and return the answer text.
|
| 103 |
+
"""
|
| 104 |
+
if qa_pipeline is None:
|
| 105 |
+
return "⚠️ QA pipeline not initialized."
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
result = qa_pipeline.invoke(query) # for LCEL chain
|
| 109 |
+
return result
|
| 110 |
+
except Exception as e:
|
| 111 |
+
return f"❌ QA run failed: {e}"
|