BuddyMath / tests /inspector.py
dotandru's picture
Fix: Clean production deployment with sse-starlette
9d29c62
Raw
History Blame Contribute Delete
1.84 kB
import requests
import base64
import json
import time
import os
import sys
# ื”ื’ื“ืจื•ืช
API_URL = "http://127.0.0.1:8000/solve_stream"
TEST_IMAGE_PATH = "test_image.png"
def run_inspection_safe():
print("๐Ÿ›‘ SAFETY CHECK: This script will trigger 1 LLM call.")
print(" Estimated cost: $0.0016")
confirm = input(" Type 'yes' to proceed: ")
if confirm.lower() != 'yes':
print("โŒ Aborted by user.")
return
# --- ืžื›ืืŸ ื”ืงื•ื“ ื–ื”ื” ืœืงื•ื“ื, ืจืฅ ืคืขื ืื—ืช ื‘ื“ื™ื•ืง ---
print("\n๐Ÿš€ Starting Single Run Inspection...")
if not os.path.exists(TEST_IMAGE_PATH):
print(f"โŒ Error: Image file '{TEST_IMAGE_PATH}' not found.")
return
files = {'file': ('test.png', open(TEST_IMAGE_PATH, 'rb'), 'image/png')}
data = {'grade': 'Test', 'mode': 'solve', 'student_name': 'Tester'}
try:
start_time = time.time()
# Timeout ื—ื•ื‘ื”! ืžื•ื ืข ื”ืžืชื ื” ืื™ื ืกื•ืคื™ืช
response = requests.post(API_URL, files=files, data=data, timeout=60)
print(f"โœ… Status Code: {response.status_code}")
print(f"โฑ๏ธ Time: {time.time() - start_time:.2f}s")
if response.status_code == 200:
try:
data = response.json()
print("โœ… JSON Valid")
print(f"๐Ÿ”‘ Keys found: {list(data.keys())}")
if "sections" in data:
print(f"๐Ÿ“„ Sections count: {len(data['sections'])}")
except:
print("โš ๏ธ Not a JSON response")
print(response.text[:200])
else:
print("โŒ Server Error")
print(response.text)
except Exception as e:
print(f"โŒ Connection Error: {e}")
if __name__ == "__main__":
run_inspection_safe()