|
|
| """
|
| 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"""
|
|
|
|
|
| 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()
|
|
|
|
|
| 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()
|
|
|