Skip to content

Commit e2636c6

Browse files
authored
Merge pull request #17 from Siquan-lab/master
ai review test
2 parents 9ff4890 + 54c8e5a commit e2636c6

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

.github/scripts/ai_code_review.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import openai
21
import os
32
import requests
3+
import openai
44

55
def load_diff(file_path='pr.diff'):
66
"""Load the diff content from file."""
@@ -11,8 +11,13 @@ def load_diff(file_path='pr.diff'):
1111
return f.read()
1212

1313
def call_gpt(diff_text):
14-
"""Call OpenAI API to review the diff content."""
15-
openai.api_key = os.getenv("OPENAI_API_KEY")
14+
"""Call AI to review the diff."""
15+
api_key = os.getenv("OPENAI_API_KEY")
16+
if not api_key:
17+
raise ValueError("❌ OPENAI_API_KEY is not set.")
18+
19+
client = openai.OpenAI(api_key=api_key, base_url='https://llm-proxy.us-east-2.int.infra.intelligence.webex.com/azure/v1?api-version=2024-10-21',default_headers={"api-key": api_key})
20+
1621
prompt = f"""
1722
You are a senior Java code reviewer.
1823
@@ -36,20 +41,22 @@ def call_gpt(diff_text):
3641
...
3742
3843
Here is the diff:
44+
3945
```
4046
{diff_text}
4147
```
4248
"""
49+
4350
print("🚀 Sending diff to AI for review...")
44-
response = openai.ChatCompletion.create(
45-
model="gpt-4",
51+
response = client.chat.completions.create(
52+
model="gpt-4o",
4653
messages=[
4754
{"role": "system", "content": "You are a Java code review expert."},
4855
{"role": "user", "content": prompt}
4956
],
5057
temperature=0.2
5158
)
52-
return response['choices'][0]['message']['content']
59+
return response.choices[0].message.content
5360

5461
def post_pr_comment(review_text):
5562
"""Post review result as a comment on the PR."""
@@ -82,3 +89,4 @@ def main():
8289

8390
if __name__ == "__main__":
8491
main()
92+

.github/workflows/ai_code_review.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@ on:
44
pull_request:
55
types: [opened, synchronize, reopened]
66

7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
711
jobs:
8-
review:
12+
AI-Review:
913
runs-on: ubuntu-latest
1014

1115
steps:
12-
- name: Set up Python
16+
- name: ✅ Checkout PR code
17+
uses: actions/checkout@v3
18+
19+
- name: 🔍 Debug workspace structure
20+
run: ls -R .github
21+
22+
- name: 🐍 Set up Python
1323
uses: actions/setup-python@v4
1424
with:
1525
python-version: '3.10'
1626

17-
- name: Install dependencies
27+
- name: 📦 Install dependencies
1828
run: pip install openai requests
1929

20-
- name: Download PR diff via GitHub API
30+
- name: 🧾 Download PR diff via GitHub API
2131
env:
2232
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2333
GITHUB_REPOSITORY: ${{ github.repository }}
@@ -28,7 +38,7 @@ jobs:
2838
https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER \
2939
-o pr.diff
3040
31-
- name: Run AI code review
41+
- name: 🤖 Run AI code review
3242
env:
3343
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
3444
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/test/java/net/lvsq/jgossip/BuggyCalculator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.logging.Logger;
1010

1111
public class BuggyCalculator {
12-
1312
private static final Logger logger = Logger.getLogger(BuggyCalculator.class.getName());
1413

1514
public double divide(int numerator, int denominator) {

0 commit comments

Comments
 (0)