Spaces:
Sleeping
Sleeping
Ensure robust fallback works without API keys
Browse files- test_api_directly.py +15 -15
- test_api_settings.py +13 -0
test_api_directly.py
CHANGED
|
@@ -10,20 +10,20 @@ except:
|
|
| 10 |
print(x)"""
|
| 11 |
|
| 12 |
print("Test 1: Simple code with bare except")
|
| 13 |
-
print("
|
| 14 |
print(code1)
|
| 15 |
-
print("
|
| 16 |
|
| 17 |
try:
|
| 18 |
response = requests.post(
|
| 19 |
"http://127.0.0.1:7860/api/review",
|
| 20 |
json={"code": code1, "language": "python"},
|
| 21 |
-
timeout=3
|
| 22 |
)
|
| 23 |
-
|
| 24 |
data = response.json()
|
| 25 |
print(f"Bugs found: {data['bugs_found']}")
|
| 26 |
-
for i, bug in enumerate(data[
|
| 27 |
print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
|
| 28 |
except Exception as e:
|
| 29 |
print(f"Error: {e}")
|
|
@@ -36,20 +36,20 @@ b = 10
|
|
| 36 |
result = a + b"""
|
| 37 |
|
| 38 |
print("Test 2: Type error")
|
| 39 |
-
print("
|
| 40 |
print(code2)
|
| 41 |
-
print("
|
| 42 |
|
| 43 |
try:
|
| 44 |
response = requests.post(
|
| 45 |
"http://127.0.0.1:7860/api/review",
|
| 46 |
json={"code": code2, "language": "python"},
|
| 47 |
-
timeout=3
|
| 48 |
)
|
| 49 |
-
|
| 50 |
data = response.json()
|
| 51 |
print(f"Bugs found: {data['bugs_found']}")
|
| 52 |
-
for i, bug in enumerate(data[
|
| 53 |
print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
|
| 54 |
except Exception as e:
|
| 55 |
print(f"Error: {e}")
|
|
@@ -60,20 +60,20 @@ print("\n")
|
|
| 60 |
code3 = """query = f'SELECT * FROM users WHERE id={user_id}'"""
|
| 61 |
|
| 62 |
print("Test 3: SQL Injection")
|
| 63 |
-
print("
|
| 64 |
print(code3)
|
| 65 |
-
print("
|
| 66 |
|
| 67 |
try:
|
| 68 |
response = requests.post(
|
| 69 |
"http://127.0.0.1:7860/api/review",
|
| 70 |
json={"code": code3, "language": "python"},
|
| 71 |
-
timeout=3
|
| 72 |
)
|
| 73 |
-
|
| 74 |
data = response.json()
|
| 75 |
print(f"Bugs found: {data['bugs_found']}")
|
| 76 |
-
for i, bug in enumerate(data[
|
| 77 |
print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Error: {e}")
|
|
|
|
| 10 |
print(x)"""
|
| 11 |
|
| 12 |
print("Test 1: Simple code with bare except")
|
| 13 |
+
print("-" * 60)
|
| 14 |
print(code1)
|
| 15 |
+
print("-" * 60)
|
| 16 |
|
| 17 |
try:
|
| 18 |
response = requests.post(
|
| 19 |
"http://127.0.0.1:7860/api/review",
|
| 20 |
json={"code": code1, "language": "python"},
|
| 21 |
+
timeout=3,
|
| 22 |
)
|
| 23 |
+
|
| 24 |
data = response.json()
|
| 25 |
print(f"Bugs found: {data['bugs_found']}")
|
| 26 |
+
for i, bug in enumerate(data["bugs"], 1):
|
| 27 |
print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
|
| 28 |
except Exception as e:
|
| 29 |
print(f"Error: {e}")
|
|
|
|
| 36 |
result = a + b"""
|
| 37 |
|
| 38 |
print("Test 2: Type error")
|
| 39 |
+
print("-" * 60)
|
| 40 |
print(code2)
|
| 41 |
+
print("-" * 60)
|
| 42 |
|
| 43 |
try:
|
| 44 |
response = requests.post(
|
| 45 |
"http://127.0.0.1:7860/api/review",
|
| 46 |
json={"code": code2, "language": "python"},
|
| 47 |
+
timeout=3,
|
| 48 |
)
|
| 49 |
+
|
| 50 |
data = response.json()
|
| 51 |
print(f"Bugs found: {data['bugs_found']}")
|
| 52 |
+
for i, bug in enumerate(data["bugs"], 1):
|
| 53 |
print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
|
| 54 |
except Exception as e:
|
| 55 |
print(f"Error: {e}")
|
|
|
|
| 60 |
code3 = """query = f'SELECT * FROM users WHERE id={user_id}'"""
|
| 61 |
|
| 62 |
print("Test 3: SQL Injection")
|
| 63 |
+
print("-" * 60)
|
| 64 |
print(code3)
|
| 65 |
+
print("-" * 60)
|
| 66 |
|
| 67 |
try:
|
| 68 |
response = requests.post(
|
| 69 |
"http://127.0.0.1:7860/api/review",
|
| 70 |
json={"code": code3, "language": "python"},
|
| 71 |
+
timeout=3,
|
| 72 |
)
|
| 73 |
+
|
| 74 |
data = response.json()
|
| 75 |
print(f"Bugs found: {data['bugs_found']}")
|
| 76 |
+
for i, bug in enumerate(data["bugs"], 1):
|
| 77 |
print(f"{i}. {bug['comment'][:60]} (confidence: {bug['confidence']})")
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Error: {e}")
|
test_api_settings.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
API_BASE_URL = os.environ.get("API_BASE_URL", "https://api.openai.com/v1")
|
| 5 |
+
MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4o")
|
| 6 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 7 |
+
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
|
| 8 |
+
|
| 9 |
+
print("API Settings:")
|
| 10 |
+
print(f" API_BASE_URL: {API_BASE_URL}")
|
| 11 |
+
print(f" MODEL_NAME: {MODEL_NAME}")
|
| 12 |
+
print(f" HF_TOKEN set: {HF_TOKEN is not None}")
|
| 13 |
+
print(f" OPENAI_API_KEY set: {OPENAI_API_KEY is not None}")
|