Spaces:
Sleeping
Sleeping
fix: skip LLM entirely when no API keys are configured, stop request log spam
Browse files
main.py
CHANGED
|
@@ -13,9 +13,14 @@ from training_loop import run_training
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
from agent import review as agent_review
|
| 16 |
-
|
| 17 |
-
except ImportError
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
logger = logging.getLogger(__name__)
|
| 21 |
|
|
@@ -134,7 +139,11 @@ async def review_code(request: ReviewRequest):
|
|
| 134 |
# ========================================================================
|
| 135 |
|
| 136 |
def analyze_code_with_llm(code: str, lang: str) -> list:
|
| 137 |
-
"""Use LLM-powered agent.review() to analyze code
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
try:
|
| 139 |
bugs = agent_review(code)
|
| 140 |
if not isinstance(bugs, list):
|
|
|
|
| 13 |
|
| 14 |
try:
|
| 15 |
from agent import review as agent_review
|
| 16 |
+
_AGENT_IMPORTED = True
|
| 17 |
+
except ImportError:
|
| 18 |
+
_AGENT_IMPORTED = False
|
| 19 |
+
|
| 20 |
+
# Only attempt LLM if at least one API key is actually configured
|
| 21 |
+
_HAS_ANTHROPIC = bool(os.environ.get("ANTHROPIC_API_KEY", "").strip())
|
| 22 |
+
_HAS_OPENAI = bool(os.environ.get("OPENAI_API_KEY", "").strip())
|
| 23 |
+
HAS_LLM = _AGENT_IMPORTED and (_HAS_ANTHROPIC or _HAS_OPENAI)
|
| 24 |
|
| 25 |
logger = logging.getLogger(__name__)
|
| 26 |
|
|
|
|
| 139 |
# ========================================================================
|
| 140 |
|
| 141 |
def analyze_code_with_llm(code: str, lang: str) -> list:
|
| 142 |
+
"""Use LLM-powered agent.review() to analyze code.
|
| 143 |
+
Short-circuits to pattern analysis if no API keys are configured."""
|
| 144 |
+
if not HAS_LLM:
|
| 145 |
+
logger.info("No LLM API keys configured — using pattern analysis.")
|
| 146 |
+
return analyze_code_comprehensively(code, lang)
|
| 147 |
try:
|
| 148 |
bugs = agent_review(code)
|
| 149 |
if not isinstance(bugs, list):
|