| """ |
| smoke_test_pipeline.py |
| Run from repo root: python smoke_test_pipeline.py |
| Tests pipeline.run() on 5 inputs - one per emotion class. |
| Prints per-stage latency, retrieved chunk preview, response preview. |
| """ |
|
|
| import sys |
| import json |
| sys.path.insert(0, "src") |
|
|
| from pipeline.pipeline import EmpathRAGPipeline |
|
|
| TEST_INPUTS = [ |
| { |
| "text": "I feel completely hopeless and I don't see a point anymore.", |
| "expected_emotion": "distress", |
| "expect_crisis": True, |
| }, |
| { |
| "text": "I'm so anxious about my thesis defense next week, I can't sleep.", |
| "expected_emotion": "anxiety", |
| "expect_crisis": False, |
| }, |
| { |
| "text": "My advisor rejected my work again without even reading it properly.", |
| "expected_emotion": "frustration", |
| "expect_crisis": False, |
| }, |
| { |
| "text": "Can you give me some tips on how to structure a literature review?", |
| "expected_emotion": "neutral", |
| "expect_crisis": False, |
| }, |
| { |
| "text": "I finally finished my dissertation chapter and my advisor loved it!", |
| "expected_emotion": "hopeful", |
| "expect_crisis": False, |
| }, |
| ] |
|
|
|
|
| def fmt_latency(lat: dict) -> str: |
| parts = [f"{k.replace('_ms', '')}={v}ms" for k, v in lat.items() if k != "total_ms"] |
| return "[" + " | ".join(parts) + f" | total={lat.get('total_ms', 0)}ms]" |
|
|
|
|
| def run_smoke_test(): |
| print("=" * 70) |
| print("EmpathRAG Smoke Test") |
| print("=" * 70) |
|
|
| print("\nInitialising pipeline...") |
| pipeline = EmpathRAGPipeline(use_real_guardrail=True, guardrail_threshold=0.5) |
|
|
| |
| |
| _original_check = pipeline.guardrail.check |
| def _fast_check(text, threshold=0.5): |
| return _original_check(text, threshold, skip_ig=True) |
| pipeline.guardrail.check = _fast_check |
|
|
| passed = 0 |
| failed = 0 |
| results = [] |
|
|
| for i, test in enumerate(TEST_INPUTS): |
| print(f"\n{chr(9472) * 70}") |
| print(f"Test {i+1}/5 - expected emotion: {test['expected_emotion']}") |
| print(f"Input: {test['text']}") |
|
|
| result = pipeline.run(test["text"]) |
|
|
| emotion_name = result["emotion_name"] |
| trajectory = result["trajectory"] |
| crisis = result["crisis"] |
| conf = result["crisis_confidence"] |
| chunks = result["retrieved_chunks"] |
| response = result["response"] |
| latency = result["latency_ms"] |
|
|
| emotion_ok = (emotion_name == test["expected_emotion"]) |
|
|
| if test["expect_crisis"]: |
| |
| content_ok = (crisis is True and len(response) > 20) |
| else: |
| |
| content_ok = (len(chunks) > 0 and len(response) > 20) |
|
|
| |
| fp_note = "" |
| if crisis and not test["expect_crisis"]: |
| fp_note = f" [known false positive - conf={conf:.3f}]" |
| status = "PASS*" |
| elif emotion_ok and content_ok: |
| status = "PASS" |
| else: |
| status = "FAIL" |
|
|
| if "FAIL" not in status: |
| passed += 1 |
| else: |
| failed += 1 |
|
|
| emotion_sym = "OK" if emotion_ok else "MISMATCH" |
| print(f"\nStatus : {status}{fp_note}") |
| print(f"Emotion : {emotion_name} (expected: {test['expected_emotion']}) [{emotion_sym}]") |
| print(f"Trajectory : {trajectory}") |
| print(f"Crisis : {crisis} (conf={conf:.3f}, expected={test['expect_crisis']})") |
| print(f"Chunks : {len(chunks)} retrieved") |
| if chunks: |
| preview = chunks[0][:120].replace("\n", " ") |
| print(f"Top chunk : {preview}...") |
| print(f"Response : {response[:150].replace(chr(10), ' ')}...") |
| print(f"Latency : {fmt_latency(latency)}") |
|
|
| results.append({ |
| "input": test["text"], |
| "expected_emotion": test["expected_emotion"], |
| "got_emotion": emotion_name, |
| "expected_crisis": test["expect_crisis"], |
| "got_crisis": crisis, |
| "crisis_conf": round(conf, 4), |
| "status": status, |
| }) |
|
|
| print(f"\n{'=' * 70}") |
| print(f"Results: {passed}/5 passed, {failed}/5 failed") |
|
|
| if failed == 0: |
| print("All smoke tests passed. Pipeline working end-to-end with real guardrail.") |
| else: |
| print("Check failures above.") |
| print(" emotion mismatch -> RoBERTa checkpoint issue") |
| print(" no chunks -> verify FAISS index path and SQLite annotation") |
|
|
| with open("eval/smoke_test_results.json", "w") as f: |
| json.dump({"passed": passed, "failed": failed, "per_test": results}, f, indent=2) |
| print("Results saved to eval/smoke_test_results.json") |
|
|
|
|
| if __name__ == "__main__": |
| run_smoke_test() |