Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
from fastapi.middleware.gzip import GZipMiddleware
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles
from dotenv import load_dotenv
load_dotenv()
import time
import os
from collections import defaultdict
import logging
from contextlib import asynccontextmanager

from .observability import initialise_app_info, prometheus_metrics_middleware
from .routers import analyze, auth, chat, collaboration, debugging, explanation
Expand Down
2 changes: 1 addition & 1 deletion backend/app/routers/explanation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
)
async def explain(req: CodeRequest):
lang = detect_language(req.code, req.language)
return run_explanation(req.code, lang)
return await run_explanation(req.code, lang)
3 changes: 3 additions & 0 deletions backend/app/services/ai_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
LLM_MAX_RETRIES = int(os.getenv("LLM_MAX_RETRIES", "3"))
LLM_RETRY_BACKOFF = float(os.getenv("LLM_RETRY_BACKOFF", "1.0"))

print("LLM_ENABLED =", LLM_ENABLED)
print("LLM_API_KEY exists =", bool(LLM_API_KEY))

def _get_provider_name(base_url: str) -> str:
parsed = urlparse(base_url)
hostname = parsed.hostname or ""
Expand Down
35 changes: 33 additions & 2 deletions backend/app/services/code_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time
from .ast_analyzer import analyze as ast_analyze
from dataclasses import dataclass, field
from .ai_provider import call_llm, is_enabled

# ── Language Detection ─────────────────────────────────────────────────────────
LANG_SIGNATURES: dict[str, list[str]] = {
Expand Down Expand Up @@ -1130,7 +1131,7 @@ def run_suggestions(code: str, language: str) -> dict:


# ── Explanation Engine ─────────────────────────────────────────────────────────
def run_explanation(code: str, language: str) -> dict:
async def run_explanation(code: str, language: str) -> dict:
"""Generate a plain-English explanation of the provided source code.

Args:
Expand Down Expand Up @@ -1199,10 +1200,40 @@ def run_explanation(code: str, language: str) -> dict:
"Advanced": f"A well-structured {language} codebase with {len(class_names)} class(es) and {len(funcs)} function(s). Shows advanced design patterns.",
"Expert": f"A large-scale {language} system ({len(lines)} lines). Expert-level architecture with significant abstraction layers.",
}

summary = summaries.get(complexity, f"A {language} code snippet.")

if is_enabled():

system_prompt = (
"You are a code summarization assistant. "
"Generate a concise one-sentence summary of what the code does."
)

user_prompt = f"""
Language: {language}

Code:
{code}

Return only the summary.
"""

if is_enabled():
ai_summary = await call_llm(system_prompt, user_prompt)
print("AI SUMMARY:", ai_summary) # ← already there
print("ENTERED RUN_EXPLANATION") # ← already there
print("LLM enabled?", is_enabled()) # ← already there

if ai_summary:
summary = ai_summary




return {
"language": language,
"summary": summaries.get(complexity, f"A {language} code snippet."),
"summary": summary,
"key_points": key_points,
"complexity": complexity,
"line_count": len(lines),
Expand Down
3 changes: 3 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading