sandhiyabk/AI-Code-Review-Assistant
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
๐ฌ New Features (Optional / Additive)
This project now includes three new optional, additive features. They do not modify or break any existing code โ the original review flow works exactly as before. New features are imported only if you choose to use them, and they degrade gracefully if a dependency is missing.
1. ๐ Review Quality Evaluation (core/evaluator.py)
After the review is generated, this optional module measures the quality of the review (not just whether it ran) using 4 LLM-judged metrics:
- Produces an overall quality score (0โ1), a quality label, and a plain-English interpretation that flags the weakest metric.
- Uses the same LLM backend already configured (Groq cloud by default, or your local/OpenAI-compatible backend) โ no new keys or packages.
- Async to the pipeline: the review shows first, evaluation runs after.
- Graceful fallback: if evaluation fails or no LLM is configured, returns
is_evaluated: Falseand the review still works normally. - Caching: identical code+review pairs are not re-evaluated.
Usage:
from core.evaluator import CodeReviewEvaluator
evaluator = CodeReviewEvaluator()
result = evaluator.evaluate_review(
code_input=code,
generated_review=review, # dict from the pipeline
retrieved_rules=relevant_rules, # list from ChromaDB
)
# result["overall_quality"], result["quality_label"], result["interpretation"]2. ๐ GitHub Integration (core/github_integration.py)
Review a file directly from a public GitHub repository instead of pasting code. Uses the GitHub REST API (Contents API), NOT raw URLs.
Can submit either:
- A full file URL:
https://github.com/user/repo/blob/main/file.py - Or a repo + file path + branch
Security guarantees:
- Only accepts
github.comURLs (rejects raw/gitlab/bitbucket). - Sanitizes paths against traversal (
../,~/,//, null bytes). - Never logs file content (may contain secrets).
- Optional
GITHUB_TOKENenv var for 5000 req/hr (vs 60 unauthenticated). - Enforces a 100KB file-size limit and an extension whitelist (
.py .js .ts .java .cpp .c .go .rs).
Usage:
from core.github_integration import GitHubIntegration
gh = GitHubIntegration()
file_data = gh.fetch_from_url("https://github.com/user/repo/blob/main/file.py")
# file_data["content"], file_data["file_name"], file_data["language"], ...
status = gh.get_rate_limit_status() # {"remaining": 45, "limit": 60, ...}3. ๐ฅ Streamlit UI Components (ui/components/)
Two importable components to drop into ui/app.py with minimal changes:
- `github_input.py` โ
render_github_input(): adds a "Paste code | GitHub URL" radio, fetch button, rate-limit status, and fetched-code verification. - `evaluation_display.py` โ
render_evaluation(): gauge-style overall score, 4 colored metric bars, interpretation, and an educational "What do these metrics mean?" expander.
Both are optional โ ui/app.py works unmodified without them.
๐งช Running the Tests
Install pytest first:
pip install pytestThen run:
# All new tests
python -m pytest tests/test_github_integration.py tests/test_evaluator.py -v
# Only GitHub tests (fully mocked โ no network)
python -m pytest tests/test_github_integration.py -vNote: The evaluation tests are fully hermetic โ they never call a real LLM. Fallback behavior is tested directly, and the successful path is tested with a mocked in-memory LLM, so the whole suite always runs.
๐ LLM Configuration
The app supports multiple LLM backends. It auto-detects the backend to use, and you can force a specific one with the LLM_BACKEND environment variable. The Groq cloud backend remains the default and requires no changes for existing deployments.
Auto-detection order
Explicit override always wins:LLM_BACKEND=groq|ollama|openai|customForce a specific model withLLM_MODEL.
Option 1: Groq API (Recommended โ Free)
- Get a free API key at https://console.groq.com
- Set it in your environment or
.envfile:
GROQ_API_KEY=your_key_here- (Optional) Override the model:
LLM_MODEL=openai/gpt-oss-20bOption 2: Ollama (Local โ no API key needed)
- Install Ollama from https://ollama.ai and start it (
ollama serve) - Pull the default model:
ollama pull llama3.2- Configure the app:
LLM_BACKEND=ollama
# optional: OLLAMA_HOST=http://localhost:11434
# optional: LLM_MODEL=llama3.2The review pipeline uses Ollama's OpenAI-compatible endpoint automatically.
Option 3: OpenAI (Cloud)
OPENAI_API_KEY=your_key_here
# optional: LLM_MODEL=gpt-4o-miniOption 4: Custom OpenAI-compatible endpoint (LM Studio / LocalAI, etc.)
OPENAI_BASE_URL=http://localhost:1234/v1
OPENAI_API_KEY=anything # must be non-empty for the client
LLM_MODEL=your-local-modelError handling
All LLM errors are translated into friendly, actionable messages with suggestions โ raw API errors are never shown directly to the user. If you see an error, check the sidebar status indicator to confirm which backend is active.
โ Requirements & Environment
Added to requirements.txt (existing dependencies untouched):
openai # required for Ollama / OpenAI-compatible local backendsAdded to .env.example:
GITHUB_TOKEN=optional_for_higher_rate_limits
LLM_BACKEND=ollama # optional: force a backend
OLLAMA_HOST=http://localhost:11434
LLM_MODEL=llama3.2 # optional: override default model
OPENAI_API_KEY=...
OPENAI_BASE_URL=http://localhost:1234/v1File Tree (New Files Only)
core/evaluator.py # LLM-based review quality evaluation
core/github_integration.py # GitHub REST API integration
core/llm_client.py # Unified LLM client (Groq/Ollama/OpenAI/custom)
ui/components/__init__.py
ui/components/github_input.py # Streamlit GitHub input component
ui/components/evaluation_display.py # Streamlit evaluation component
tests/test_evaluator.py # Evaluator tests
tests/test_github_integration.py # GitHub tests (mocked, no network)
.env.example # Added GITHUB_TOKEN placeholderModified additively (existing flows preserved):
core/llm_reviewer.pyโ graceful, categorized error messages + shared clientcore/pipeline.pyโ skips AST validation on LLM error resultscore/evaluator.pyโ uses the shared LLM client (Groq default preserved)ui/app.pyโ sidebar LLM-backend status indicatorapi/main.pyโ helpful error messages instead of raw tracebacksrequirements.txtโ addedopenai(optional, for local backends)
