Skip to content

Commit f4d1f47

Browse files
committed
Initial Python Code
1 parent 9a1b1fb commit f4d1f47

5 files changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/code-review.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: LLM Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
7+
jobs:
8+
review:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: '3.10'
18+
19+
- name: Install dependencies
20+
run: |
21+
pip install -r requirements.txt
22+
23+
- name: Run code review
24+
run: |
25+
python reviewbot/main.py

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LLM Code Review Bot

reviewbot/main.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import requests
3+
from reviewbot.utils import get_diff
4+
5+
def review_with_groq(diff):
6+
api_key = os.environ.get("GROQ_API_KEY")
7+
headers = {
8+
"Authorization": f"Bearer {api_key}",
9+
"Content-Type": "application/json",
10+
}
11+
payload = {
12+
"model": "mixtral-8x7b-32768",
13+
"messages": [
14+
{"role": "system", "content": "You are a senior software engineer doing code reviews."},
15+
{"role": "user", "content": f"Please review this code diff:\n\n{diff}"}
16+
],
17+
"temperature": 0.3,
18+
}
19+
20+
response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=payload)
21+
return response.json()["choices"][0]["message"]["content"]
22+
23+
def main():
24+
diff = get_diff()
25+
review = review_with_groq(diff)
26+
print("::notice file=test_module/hello.py,line=1::" + review.replace("\n", " "))
27+
28+
if __name__ == "__main__":
29+
main()

reviewbot/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# reviewbot/utils.py
2+
3+
def get_diff():
4+
# In real setup, parse `git diff` or PR files
5+
return "def hello(name):\n print('Hello ' + name)"
6+
7+
def fake_llm_review(diff):
8+
if "print" in diff:
9+
return "Consider using logging instead of print for better production code quality."
10+
return "No issues found."

test_module/hello.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# test_module/hello.py
2+
3+
def hello(name):
4+
print("Hello " + name)
5+
6+
hello("World")

0 commit comments

Comments
 (0)