Team Ai
Apppublic

suryanshp1/code-reviewer-ci

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
App README

๐Ÿค– AI Code Reviewer Agent

Production-ready AI-powered code review using CrewAI multi-agent framework

Automatically review code changes with specialized AI agents analyzing security, performance, code quality, and maintainability.

๐Ÿš€ Quick Start

API Endpoints

Health Check
bash
curl https://YOUR-USERNAME-YOUR-SPACE.hf.space/health
Code Review
bash
curl -X POST https://YOUR-USERNAME-YOUR-SPACE.hf.space/review \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "diff": "diff --git a/app.py b/app.py\n+def login(user, pwd):\n+    query = f\"SELECT * FROM users WHERE user='\''{user}'\''\"",
    "language": "python",
    "context": {
      "repo": "myorg/myrepo",
      "pr_number": 123
    }
  }'

๐Ÿ“Š Multi-Agent Architecture

This system uses 5 specialized AI agents working in parallel:

AgentRoleFocus
๐Ÿ” Code AnalyzerSenior EngineerLogic, complexity, architecture
๐Ÿ”’ Security ReviewerAppSec EngineerVulnerabilities, injection attacks
โšก Performance ReviewerPerformance EngineerN+1 queries, algorithmic complexity
โœจ Style ReviewerStaff EngineerNaming, maintainability, SOLID
๐Ÿ“ Review SynthesizerTech LeadPrioritization, final report

โš™๏ธ Configuration

Environment Variables

Required (set in Space Settings โ†’ Variables):

  • โ€”LLM_PROVIDER - openai or groq
  • โ€”OPENAI_API_KEY or GROQ_API_KEY - Your LLM API key
  • โ€”REVIEW_API_KEY - API key for authenticating requests

Optional:

  • โ€”RATE_LIMIT_PER_MINUTE - Max requests per minute (default: 5)
  • โ€”REQUEST_TIMEOUT_SECONDS - Review timeout (default: 90)
  • โ€”MAX_FINDINGS_PER_REVIEW - Max findings to return (default: 15)

Recommended LLM Configuration

For Free Tier:

bash
LLM_PROVIDER=groq
GROQ_API_KEY=gsk_your_key_here
GROQ_MODEL=llama-3.3-70b-versatile

For Production:

bash
LLM_PROVIDER=openai
OPENAI_API_KEY=sk_your_key_here
OPENAI_MODEL=gpt-4o-mini

๐Ÿ“ API Response Format

json
{
  "summary": "Found 2 security issues and 1 performance concern",
  "score": 7.5,
  "findings": [
    {
      "category": "security",
      "severity": "high",
      "file": "app/auth.py",
      "line": 24,
      "message": "SQL injection vulnerability detected",
      "suggestion": "Use parameterized queries instead of string interpolation"
    }
  ],
  "metadata": {
    "execution_time_ms": 15234,
    "tokens_used": 12453,
    "agent_count": 5,
    "model": "gpt-4o-mini"
  }
}

๐Ÿ”ง GitHub Integration

Integrate with your CI/CD pipeline:

yaml
# .github/workflows/code-review.yml
- name: AI Code Review
  run: |
    curl -X POST https://YOUR-SPACE.hf.space/review \
      -H "Authorization: Bearer ${{ secrets.REVIEW_API_KEY }}" \
      -d @review_request.json

๐Ÿ“ˆ Performance

MetricValue
Avg review time15-45 seconds
Max diff size1 MB
Token usage~10K per review
Cost per review$0.002 - $0.15

โš ๏ธ Limitations on Free Tier

  • โ€”Single worker: Can handle 1 request at a time
  • โ€”Cold starts: First request after sleep takes ~60 seconds
  • โ€”Resource limits: 2 vCPU, 16GB RAM
  • โ€”Timeouts: Long reviews may timeout (increase REQUEST_TIMEOUT_SECONDS)

๐Ÿ”’ Security

  • โ€”API key authentication required for /review endpoint
  • โ€”Rate limiting prevents abuse
  • โ€”No data persistence (stateless reviews)
  • โ€”Secrets managed via HF Space settings

๐Ÿ“š Documentation

Full documentation: GitHub Repository

๐Ÿ’ก Tips

  1. 1.Use Groq for free tier - Faster and free API calls
  2. 2.Keep diffs small - Large changes may timeout
  3. 3.Set rate limits - Prevent quota exhaustion
  4. 4.Monitor usage - Track LLM API costs

๐Ÿ™ Credits

Built with:


Made with โค๏ธ for better code reviews