hallucination-detector-project / debug_prediction.py
KShoichi's picture
Upload debug_prediction.py with huggingface_hub
2e4d3f7 verified
#!/usr/bin/env python3
"""
Quick test to see what the model is actually predicting
"""
import requests
import json
BASE_URL = "http://localhost:8000"
def test_single_prediction():
"""Test a single prediction to see raw output"""
# Test obvious hallucination
payload = {
"prompt": "Question: What is the capital of France?",
"response": "London is the capital of France",
"question": "What is the capital of France?"
}
print("πŸ§ͺ Testing obvious hallucination:")
print(f"Question: {payload['question']}")
print(f"Response: {payload['response']}")
print(f"Expected: HALLUCINATION")
print()
try:
response = requests.post(f"{BASE_URL}/api/debug-predict", json=payload, timeout=10)
if response.status_code == 200:
result = response.json()
print("πŸ“Š Debug Results:")
print(f"Raw Model Output: '{result.get('raw_model_output', '')}'")
print(f"Extracted Prediction: '{result.get('extracted_prediction', '')}'")
print(f"Is Hallucination: {result.get('is_hallucination', False)}")
print(f"Confidence Score: {result.get('confidence_score', 0):.3f}")
print()
# Also test regular API
response2 = requests.post(f"{BASE_URL}/api/predict", json=payload, timeout=10)
if response2.status_code == 200:
result2 = response2.json()
print("πŸ“Š Regular API Results:")
print(f"Is Hallucination: {result2.get('is_hallucination', False)}")
print(f"Confidence Score: {result2.get('confidence_score', 0):.3f}")
print(f"Raw Prediction: '{result2.get('raw_prediction', '')}'")
else:
print(f"❌ Error: {response.status_code}")
print(response.text)
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
test_single_prediction()