| title | Legacy: AI-Powered Code Reviews |
|---|---|
| slug | legacy/tutorials/ai-powered-reviews |
OpenCodeHub integrates with LLMs (GPT-4, Claude) to provide automated, intelligent code reviews on every Pull Request. This tutorial guides you through setting it up.
- An OpenCodeHub instance running v1.0.0+.
- An API Key from OpenAI or Anthropic.
As an administrator, you need to configure the AI provider in your environment variables.
For OpenAI:
AI_PROVIDER=openai
OPENAI_API_KEY=sk-proj-...For Anthropic:
AI_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-...Restart your OpenCodeHub instance to apply changes.
By default, AI review is opt-in per repository to save costs.
- Navigate to Repository Settings > AI Review.
- Toggle Enable AI Review.
- Select Triggers:
- On PR Open: Reviews the initial code.
- On Every Push: Reviews every update (Can be expensive).
- Manual Only: Developers must click "Request AI Review".
- Create a Pull Request with some code.
- If configured for "Manual Only", look for the "🤖 Request AI Review" button in the PR sidebar. Click it.
- Wait a few seconds (or minutes for large PRs).
- The AI will comment directly on lines of code with:
- 🔴 Security Risks: SQL injection, hardcoded secrets.
- 🟡 Bugs: Null pointer exceptions, logic errors.
- 🔵 Suggestions: Code style, minor performance tweaks.
You can customize the system prompt used for reviews by editing src/lib/ai/prompts.ts if you are self-hosting and want to enforce specific coding standards.