|
1 | | -# Friendly AI Reviewer (FAIR) Setup Guide |
| 1 | +# Friendly AI Reviewer Setup Guide |
2 | 2 |
|
3 | 3 | - Creates highly-customizable AI Reviews as PR comments. |
4 | | -- Installation: Just 2 files copied to your repo and a open router API Key in your secrets. |
5 | | -- Costs: $0.01 - $0.05 per review (depends highly on model) |
6 | | -- ** Example output ** https://github.com/LearningCircuit/local-deep-research/pull/959#issuecomment-3445396169 |
| 4 | +- Installation: Just 2 files copied to your repo and an OpenRouter API Key in your secrets. |
| 5 | +- Costs: $0.01 - $0.05 per review (even for large PRs with full context) |
| 6 | +- **Example output**: https://github.com/LearningCircuit/local-deep-research/pull/959#issuecomment-3445396169 |
7 | 7 |
|
8 | 8 | This guide explains how to set up the automated AI PR review system using OpenRouter to analyze pull requests with your choice of AI model. |
9 | 9 |
|
| 10 | +## What's New |
| 11 | + |
| 12 | +**Latest Updates:** |
| 13 | +- **Thinking Model Support**: Now supports advanced reasoning models like Kimi K2 that use `<thinking>` tags |
| 14 | +- **Rich Context**: Includes PR descriptions, commit messages, and human comments for comprehensive reviews |
| 15 | +- **Higher Token Limits**: Default 64k tokens for complete reviews without truncation |
| 16 | +- **Smart Context Management**: Only fetches most recent AI review to save tokens |
| 17 | +- **Enhanced Error Handling**: Robust parsing of various AI response formats |
| 18 | + |
10 | 19 | ## Overview |
11 | 20 |
|
12 | 21 | The AI Code Reviewer provides automated, comprehensive code reviews covering: |
@@ -45,12 +54,20 @@ The review is posted as a single comprehensive comment on your pull request with |
45 | 54 |
|
46 | 55 | ### 3. Configure Workflow (Optional) |
47 | 56 |
|
48 | | -The workflow is pre-configured with sensible defaults, but you can customize it by editing `.github/workflows/ai-code-reviewer.yml`: |
| 57 | +The workflow is pre-configured with sensible defaults, but you can customize it by setting repository variables in **Settings** → **Secrets and variables** → **Actions** → **Variables**: |
49 | 58 |
|
50 | | -- **AI_MODEL**: Change the AI model (see [OpenRouter models](https://openrouter.ai/models)) |
| 59 | +- **AI_MODEL**: Change the AI model (default: `moonshotai/kimi-k2-thinking`) |
| 60 | + - See [OpenRouter models](https://openrouter.ai/models) for options |
| 61 | + - Recommended: Models with reasoning capabilities (Kimi K2, o1, etc.) |
51 | 62 | - **AI_TEMPERATURE**: Adjust randomness (default: `0.1` for consistent reviews) |
52 | | -- **AI_MAX_TOKENS**: Maximum response length (default: `2000`) |
| 63 | +- **AI_MAX_TOKENS**: Maximum response length (default: `64000`) |
| 64 | + - High limit ensures comprehensive reviews without truncation |
| 65 | + - For large PRs with thinking models, this prevents cut-off responses |
| 66 | + - Adjust lower for cost savings on smaller PRs |
53 | 67 | - **MAX_DIFF_SIZE**: Maximum diff size in bytes (default: `800000` / 800KB) |
| 68 | +- **DEBUG_MODE**: Enable debug logging (default: `false`) |
| 69 | + - ⚠️ Warning: Exposes code diff in workflow logs when enabled |
| 70 | + - Only enable temporarily for troubleshooting |
54 | 71 |
|
55 | 72 | ## Usage |
56 | 73 |
|
@@ -79,11 +96,31 @@ The AI posts a comprehensive comment analyzing your code across all focus areas. |
79 | 96 |
|
80 | 97 | ## Cost Estimation |
81 | 98 |
|
82 | | -Costs vary by model, but most code-focused models on OpenRouter are very affordable: |
83 | | -- Typical small PR (< 1000 lines): $0.001 - $0.01 |
84 | | -- Large PR (1000-5000 lines): $0.01 - $0.05 |
| 99 | +Costs with the default Kimi K2 thinking model are very affordable. Based on real usage data: |
| 100 | + |
| 101 | +**Typical Costs:** |
| 102 | +- Small PR (< 1000 lines): $0.01 - $0.02 |
| 103 | +- Medium PR (1000-3000 lines): $0.02 - $0.04 |
| 104 | +- Large PR (3000+ lines): $0.04 - $0.06 |
| 105 | + |
| 106 | +**Example from a 20-commit PR with full context:** |
| 107 | +- Input: ~5,000-9,000 tokens (diff + PR description + commits + human comments) |
| 108 | +- Output: ~2,000-6,000 tokens (comprehensive review) |
| 109 | +- **Total cost: $0.01 - $0.05 per review** |
| 110 | + |
| 111 | +**Why So Affordable:** |
| 112 | +- Kimi K2 has competitive pricing (~$0.001-$0.003 per 1k tokens) |
| 113 | +- Smart context management (only most recent AI review, limited commit history) |
| 114 | +- Most PRs are smaller than you think in token count |
| 115 | +- The 64k token limit is a ceiling, not typical usage |
| 116 | + |
| 117 | +**Cost varies based on:** |
| 118 | +- PR size (larger diffs = more input tokens) |
| 119 | +- Review complexity (detailed reviews = more output tokens) |
| 120 | +- Number of human comments and commit messages included |
| 121 | +- OpenRouter provider routing (prices vary slightly by provider) |
85 | 122 |
|
86 | | -Check [OpenRouter pricing](https://openrouter.ai/models) for specific model costs. |
| 123 | +Check [OpenRouter pricing](https://openrouter.ai/models) for current Kimi K2 rates. |
87 | 124 |
|
88 | 125 | ## Customization |
89 | 126 |
|
@@ -138,11 +175,14 @@ If you get a "Diff is too large" error: |
138 | 175 |
|
139 | 176 | The workflow fetches and sends these repository elements to the AI: |
140 | 177 | 1. **Code Changes**: Full diff of modified files |
141 | | -2. **Labels**: All repository labels with descriptions and colors |
142 | | -3. **Previous Comments**: All previous AI review comments from the PR |
143 | | -4. **CI/CD Status**: GitHub Actions check runs and build statuses |
144 | | -5. **PR Metadata**: Pull request details, head SHA, repository information |
145 | | -6. **Files**: May include sensitive configuration files, keys, or credentials |
| 178 | +2. **PR Description**: Title and description text from the pull request |
| 179 | +3. **Commit Messages**: Up to 15 most recent commit messages (excluding merges) |
| 180 | +4. **Human Comments**: All comments from human reviewers on the PR |
| 181 | +5. **Labels**: All repository labels with descriptions and colors |
| 182 | +6. **Previous AI Review**: Most recent AI review comment only (limited to 10k chars) |
| 183 | +7. **CI/CD Status**: GitHub Actions check runs and build statuses |
| 184 | +8. **PR Metadata**: Pull request details, head SHA, repository information |
| 185 | +9. **Files**: May include sensitive configuration files, keys, or credentials |
146 | 186 |
|
147 | 187 | ### Recommended Mitigations |
148 | 188 |
|
|
0 commit comments