Skip to content

Commit ad2f491

Browse files
authored
Merge pull request #1 from aimenng/copilot/enable-gpt-codex-review
Upgrade AI code review to GPT-4 Turbo with optimized parameters
2 parents f9a5cc4 + d928934 commit ad2f491

6 files changed

Lines changed: 499 additions & 0 deletions

File tree

.github/GPT_CODE_REVIEW_SETUP.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# GPT-4 Turbo 顶配代码审查设置指南
2+
3+
本仓库已启用基于 **GPT-4 Turbo Preview** 的自动代码审查功能,采用顶级配置以提供最优质的代码审查体验。
4+
5+
## 功能特性
6+
7+
- ✅ 自动审查所有 Pull Request 的代码变更
8+
- ✅ 使用 **GPT-4 Turbo Preview** 模型(最新最强大的模型)
9+
- ✅ 支持中文反馈
10+
- ✅ 自动识别代码问题、潜在 bug 和改进建议
11+
-**顶配参数**:更大的 token 容量,更精确的输出
12+
13+
## 配置步骤
14+
15+
### 1. 获取 OpenAI API Key
16+
17+
1. 访问 [OpenAI Platform](https://platform.openai.com/)
18+
2. 创建账号并登录
19+
3. 进入 API Keys 页面:https://platform.openai.com/api-keys
20+
4. 点击 "Create new secret key" 创建新的 API key
21+
5. 复制生成的 key(只会显示一次)
22+
23+
### 2. 配置 GitHub Secrets
24+
25+
1. 进入仓库的 Settings
26+
2. 点击左侧菜单的 "Secrets and variables" → "Actions"
27+
3. 点击 "New repository secret"
28+
4. 添加以下 secret:
29+
- Name: `OPENAI_API_KEY`
30+
- Value: 粘贴你的 OpenAI API key
31+
32+
### 3. 启用 GitHub Actions
33+
34+
1. 进入仓库的 Actions 页面
35+
2. 如果 Actions 未启用,点击 "I understand my workflows, go ahead and enable them"
36+
3. 确认 "AI Code Review" workflow 已经出现在列表中
37+
38+
## 使用方法
39+
40+
配置完成后,每当有新的 Pull Request 创建或更新时,AI 代码审查会自动触发:
41+
42+
1. 创建或更新 Pull Request
43+
2. 等待 AI Code Review workflow 运行(通常需要 1-2 分钟)
44+
3. 查看 PR 中的审查评论,AI 会直接在代码行上留下建议
45+
46+
## 工作流程配置
47+
48+
当前配置(**顶级配置**):
49+
- **模型**: GPT-4 Turbo Preview(最新最强大的模型)
50+
- **语言**: 中文 (zh-CN)
51+
- **触发条件**: PR 创建、同步、重新打开
52+
- **最大 token 数**: 4096(2倍于标准配置,支持更详细的审查)
53+
- **Temperature**: 0.2(更精确、更一致的输出)
54+
- **Top P**: 0.95(高质量输出)
55+
56+
### 配置优势
57+
58+
与标准 GPT-4 配置相比:
59+
- 🚀 **更强大的模型**:GPT-4 Turbo 拥有更强的理解和推理能力
60+
- 📝 **更详细的反馈**:4096 tokens 支持更深入的代码分析
61+
- 🎯 **更精确的建议**:降低的 temperature 确保输出更稳定可靠
62+
- 💰 **更高性价比**:GPT-4 Turbo 价格更低但性能更强
63+
64+
## 自定义配置
65+
66+
如需修改配置,编辑 `.github/workflows/ai-code-review.yml` 文件:
67+
68+
```yaml
69+
env:
70+
MODEL: gpt-4-turbo-preview # 可选: gpt-4-turbo-preview, gpt-4, gpt-3.5-turbo
71+
LANGUAGE: zh-CN # 可选: zh-CN (中文), en-US (英文)
72+
MAX_TOKENS: 4096 # 每次审查的最大 token 数
73+
TEMPERATURE: 0.2 # 0-1 之间,值越低输出越确定
74+
TOP_P: 0.95 # 0-1 之间,控制输出多样性
75+
```
76+
77+
## 成本估算
78+
79+
GPT-4 Turbo Preview 定价(**更实惠**):
80+
- 输入:$0.01 / 1K tokens(比 GPT-4 便宜 67%)
81+
- 输出:$0.03 / 1K tokens(比 GPT-4 便宜 50%)
82+
- 每次代码审查通常使用 1000-4000 tokens
83+
- 估算成本:每次审查约 $0.05-0.15
84+
- 建议设置 OpenAI 账户的月度预算上限
85+
86+
💡 **提示**:虽然使用了更强大的模型和更大的 token 容量,但 GPT-4 Turbo 的价格更低,性价比更高!
87+
88+
## 注意事项
89+
90+
1. **API Key 安全**:
91+
- 永远不要在代码中硬编码 API key
92+
- 只通过 GitHub Secrets 管理敏感信息
93+
94+
2. **成本控制**:
95+
- 建议在 OpenAI 账户中设置使用限额
96+
- 可以根据需要调整 MAX_TOKENS 降低成本
97+
98+
3. **审查质量**:
99+
- AI 建议仅供参考,最终决策由开发者做出
100+
- 对于关键代码,仍需人工审查
101+
102+
4. **隐私考虑**:
103+
- 代码会发送到 OpenAI API 进行分析
104+
- 确保符合项目的隐私和安全要求
105+
106+
## 故障排除
107+
108+
### Workflow 未触发
109+
- 检查 GitHub Actions 是否已启用
110+
- 确认 `.github/workflows/ai-code-review.yml` 文件存在
111+
112+
### API Key 错误
113+
- 验证 `OPENAI_API_KEY` secret 是否正确配置
114+
- 确认 API key 有效且有足够的配额
115+
116+
### 无审查评论
117+
- 检查 PR 是否有代码变更
118+
- 查看 Actions 日志了解详细错误信息
119+
120+
## 更多资源
121+
122+
- [ChatGPT-CodeReview Action](https://github.com/anc95/ChatGPT-CodeReview)
123+
- [OpenAI API 文档](https://platform.openai.com/docs)
124+
- [GitHub Actions 文档](https://docs.github.com/en/actions)
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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)

.github/SETUP_COMPLETE.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# GPT-4 Turbo 顶配代码审查已成功启用!
2+
3+
## ✅ 已完成的配置
4+
5+
1. **创建 GitHub Actions 工作流**
6+
- 文件:`.github/workflows/ai-code-review.yml`
7+
- 功能:自动审查所有 Pull Request
8+
- **升级到 GPT-4 Turbo Preview 顶配**
9+
10+
2. **详细设置文档**
11+
- 中文文档:`.github/GPT_CODE_REVIEW_SETUP.md`
12+
- English: `.github/GPT_CODE_REVIEW_SETUP_EN.md`
13+
14+
3. **更新主 README**
15+
- 添加了 AI Code Review 功能的说明和链接
16+
17+
## 🚀 下一步操作
18+
19+
### 立即需要做的:
20+
21+
1. **配置 OpenAI API Key** (必需)
22+
- 访问:https://platform.openai.com/api-keys
23+
- 创建新的 API key
24+
- 在 GitHub 仓库添加 Secret:
25+
- 进入:Settings → Secrets and variables → Actions
26+
- 添加名为 `OPENAI_API_KEY` 的 secret
27+
28+
2. **启用 GitHub Actions** (如果尚未启用)
29+
- 进入仓库的 Actions 页面
30+
- 点击启用 workflows
31+
32+
### 测试工作流:
33+
34+
1. 创建一个新的 Pull Request
35+
2. 等待 "AI Code Review" workflow 运行
36+
3. 查看 PR 中的 AI 审查评论
37+
38+
## 🔧 配置详情(**顶级配置**
39+
40+
- ✨ 使用 **GPT-4 Turbo Preview** 模型(最新最强)
41+
- 🌏 中文审查反馈
42+
- 🤖 自动触发于 PR 创建/更新
43+
- 💬 直接在代码行上留下评论
44+
- 🔍 识别潜在问题和改进建议
45+
- 📊 **4096 tokens**:支持更详细深入的代码分析
46+
- 🎯 **Temperature 0.2**:更精确一致的输出
47+
- 🚀 **更高性价比**:性能更强但成本更低
48+
49+
## 📖 详细文档
50+
51+
查看完整的设置和使用说明:
52+
- 中文: [GPT_CODE_REVIEW_SETUP.md](.github/GPT_CODE_REVIEW_SETUP.md)
53+
- English: [GPT_CODE_REVIEW_SETUP_EN.md](.github/GPT_CODE_REVIEW_SETUP_EN.md)
54+
55+
## 💰 成本说明(**更实惠的顶配**
56+
57+
GPT-4 Turbo Preview 定价:
58+
- 输入:$0.01/1K tokens(比标准 GPT-4 便宜 67%)
59+
- 输出:$0.03/1K tokens(比标准 GPT-4 便宜 50%)
60+
- 每次审查约 $0.05-0.15
61+
- 建议在 OpenAI 账户设置月度预算上限
62+
63+
💡 **优势**:虽然使用了更强大的模型和 4096 tokens 容量,但 GPT-4 Turbo 的价格更低,性价比极高!
64+
65+
## 🔒 安全提示
66+
67+
- ✅ API Key 已通过 GitHub Secrets 安全管理
68+
- ✅ 工作流只对 Pull Request 触发
69+
- ⚠️ 代码会发送到 OpenAI API 进行分析
70+
- ⚠️ 确保符合项目的隐私和合规要求
71+
72+
---
73+
74+
**需要帮助?** 查看详细文档或联系仓库维护者

0 commit comments

Comments
 (0)