Spaces:
Sleeping
Sleeping
File size: 1,908 Bytes
8b06b9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #!/usr/bin/env python
"""Test the new LLM-powered API"""
import requests
import json
import time
BASE_URL = "http://localhost:7860"
# Test code with SQL injection
test_code = '''def get_user(uid):
q = f"SELECT * FROM users WHERE id={uid}"
cursor.execute(q)
return cursor.fetchone()
'''
print("=" * 60)
print("TEST 1: SQL Injection Detection (LLM)")
print("=" * 60)
payload = {
"code": test_code,
"language": "python"
}
try:
response = requests.post(f"{BASE_URL}/api/review", json=payload, timeout=10)
print(f"Status: {response.status_code}")
data = response.json()
print(f"\n✓ Bugs found: {data.get('bugs_found', 0)}")
if data.get('bugs'):
for i, bug in enumerate(data['bugs'], 1):
print(f"\nBug #{i}:")
print(f" Category: {bug.get('category')}")
print(f" Severity: {bug.get('severity')}/5")
print(f" Confidence: {bug.get('confidence', 0):.2f}")
print(f" Comment: {bug.get('comment', 'N/A')}")
print(f"\nAverage Confidence: {data.get('analysis_metadata', {}).get('average_confidence', 'N/A')}")
except Exception as e:
print(f"✗ Error: {e}")
print("\n" + "=" * 60)
print("TEST 2: Clean Code")
print("=" * 60)
clean_code = '''def add(a, b):
return a + b
'''
payload = {
"code": clean_code,
"language": "python"
}
try:
response = requests.post(f"{BASE_URL}/api/review", json=payload, timeout=10)
print(f"Status: {response.status_code}")
data = response.json()
print(f"✓ Bugs found: {data.get('bugs_found', 0)}")
if data.get('primary_bug'):
bug = data['primary_bug']
print(f" Result: {bug.get('comment', 'No issues')}")
print(f" Confidence: {bug.get('confidence', 1.0)}")
except Exception as e:
print(f"✗ Error: {e}")
print("\n" + "=" * 60)
print("DONE!")
print("=" * 60)
|