|
| 1 | +# GPT-4 Turbo Premium Code Review Setup Guide |
| 2 | + |
| 3 | +This repository has **GPT-4 Turbo Preview** powered automated code review enabled with premium configuration for the best code review experience. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- ✅ Automatically reviews all Pull Request code changes |
| 8 | +- ✅ Uses **GPT-4 Turbo Preview** model (latest and most powerful) |
| 9 | +- ✅ Supports Chinese feedback |
| 10 | +- ✅ Identifies code issues, potential bugs, and improvement suggestions |
| 11 | +- ✅ **Premium Configuration**: Higher token capacity, more precise output |
| 12 | + |
| 13 | +## Setup Steps |
| 14 | + |
| 15 | +### 1. Get OpenAI API Key |
| 16 | + |
| 17 | +1. Visit [OpenAI Platform](https://platform.openai.com/) |
| 18 | +2. Create an account and login |
| 19 | +3. Go to API Keys page: https://platform.openai.com/api-keys |
| 20 | +4. Click "Create new secret key" |
| 21 | +5. Copy the generated key (it will only be shown once) |
| 22 | + |
| 23 | +### 2. Configure GitHub Secrets |
| 24 | + |
| 25 | +1. Go to repository Settings |
| 26 | +2. Click "Secrets and variables" → "Actions" in the left menu |
| 27 | +3. Click "New repository secret" |
| 28 | +4. Add the following secret: |
| 29 | + - Name: `OPENAI_API_KEY` |
| 30 | + - Value: Paste your OpenAI API key |
| 31 | + |
| 32 | +### 3. Enable GitHub Actions |
| 33 | + |
| 34 | +1. Go to the repository's Actions page |
| 35 | +2. If Actions are not enabled, click "I understand my workflows, go ahead and enable them" |
| 36 | +3. Confirm that "AI Code Review" workflow appears in the list |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +Once configured, AI code review will automatically trigger when a Pull Request is created or updated: |
| 41 | + |
| 42 | +1. Create or update a Pull Request |
| 43 | +2. Wait for the AI Code Review workflow to run (typically 1-2 minutes) |
| 44 | +3. Check the review comments in the PR - AI will leave suggestions directly on code lines |
| 45 | + |
| 46 | +## Workflow Configuration |
| 47 | + |
| 48 | +Current configuration: |
| 49 | +- **Model**: GPT-4 |
| 50 | +- **Language**: Chinese (zh-CN) |
| 51 | +- **Trigger**: PR open, synchronize, reopen |
| 52 | +- **Max Tokens**: 2000 |
| 53 | +- **Temperature**: 0.3 (more stable output) |
| 54 | +- **Top P**: 0.9 |
| 55 | + |
| 56 | +## Custom Configuration |
| 57 | + |
| 58 | +To modify settings, edit `.github/workflows/ai-code-review.yml`: |
| 59 | + |
| 60 | +```yaml |
| 61 | +env: |
| 62 | + MODEL: gpt-4 # Options: gpt-4, gpt-4-turbo, gpt-3.5-turbo |
| 63 | + LANGUAGE: zh-CN # Options: zh-CN (Chinese), en-US (English) |
| 64 | + MAX_TOKENS: 2000 # Maximum tokens per review |
| 65 | + TEMPERATURE: 0.3 # 0-1, lower = more deterministic |
| 66 | + TOP_P: 0.9 # 0-1, controls output diversity |
| 67 | +``` |
| 68 | +
|
| 69 | +## Cost Estimation |
| 70 | +
|
| 71 | +GPT-4 Turbo Preview pricing (**More Affordable**): |
| 72 | +- Input: $0.01/1K tokens (67% cheaper than GPT-4) |
| 73 | +- Output: $0.03/1K tokens (50% cheaper than GPT-4) |
| 74 | +- Each code review typically uses 1000-4000 tokens |
| 75 | +- Estimated cost: ~$0.05-0.15 per review |
| 76 | +- Recommend setting monthly budget limits in OpenAI account |
| 77 | +
|
| 78 | +💡 **Tip**: Despite using a more powerful model and larger token capacity, GPT-4 Turbo is more cost-effective! |
| 79 | +
|
| 80 | +## Important Notes |
| 81 | +
|
| 82 | +1. **API Key Security**: |
| 83 | + - Never hardcode API keys in code |
| 84 | + - Only manage sensitive information through GitHub Secrets |
| 85 | + |
| 86 | +2. **Cost Control**: |
| 87 | + - Set usage limits in your OpenAI account |
| 88 | + - Adjust MAX_TOKENS to reduce costs if needed |
| 89 | +
|
| 90 | +3. **Review Quality**: |
| 91 | + - AI suggestions are for reference only, final decisions are made by developers |
| 92 | + - Critical code still requires human review |
| 93 | +
|
| 94 | +4. **Privacy Considerations**: |
| 95 | + - Code will be sent to OpenAI API for analysis |
| 96 | + - Ensure compliance with project privacy and security requirements |
| 97 | +
|
| 98 | +## Troubleshooting |
| 99 | +
|
| 100 | +### Workflow Not Triggering |
| 101 | +- Check if GitHub Actions is enabled |
| 102 | +- Confirm `.github/workflows/ai-code-review.yml` file exists |
| 103 | + |
| 104 | +### API Key Error |
| 105 | +- Verify `OPENAI_API_KEY` secret is correctly configured |
| 106 | +- Confirm API key is valid and has sufficient quota |
| 107 | + |
| 108 | +### No Review Comments |
| 109 | +- Check if PR has code changes |
| 110 | +- Review Actions logs for detailed error messages |
| 111 | + |
| 112 | +## Additional Resources |
| 113 | + |
| 114 | +- [ChatGPT-CodeReview Action](https://github.com/anc95/ChatGPT-CodeReview) |
| 115 | +- [OpenAI API Documentation](https://platform.openai.com/docs) |
| 116 | +- [GitHub Actions Documentation](https://docs.github.com/en/actions) |
0 commit comments