Skip to content

Commit 858cd5b

Browse files
author
Zinc Lim
committed
review_patch: Integrated claude review for series id
- Note that it only works in the EC2 instance. Run python3 "review_patch.py --series <series id>" - In future, we will refine the AI by using MCP and codebase indexing in https://github.com/facebookexperimental/semcode.git Subject Signed-off-by: Zinc Lim <[email protected]>
1 parent cac3093 commit 858cd5b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

review_patch.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,56 @@
55

66
import argparse
77
import configparser
8+
import json
9+
import os
10+
11+
import boto3
812

913
import requests
1014
from core import log, log_end_sec, log_init, log_open_sec
1115
from pw import Patchwork
1216

1317

18+
# THIS WILL ONLY WORK IN EC2 INSTANCE ENVIRONMENT
19+
def review_patch_with_bedrock(title, commit_msg, diff):
20+
bedrock = boto3.client("bedrock-runtime")
21+
22+
prompt = f"""Review this Linux kernel patch:
23+
24+
Title: {title}
25+
26+
Commit Message:
27+
{commit_msg}
28+
29+
Code Changes:
30+
{diff}
31+
32+
Please review for:
33+
1. Correctness and bugs
34+
2. Linux kernel coding style
35+
3. Memory safety
36+
4. Security concerns
37+
5. Performance implications
38+
"""
39+
40+
body_dict = {
41+
"anthropic_version": os.environ.get("BEDROCK_ANTHROPIC_VERSION"),
42+
"max_tokens": int(os.environ.get("BEDROCK_MAX_TOKENS")),
43+
"messages": [{"role": "user", "content": prompt}],
44+
}
45+
46+
body_bytes = json.dumps(body_dict).encode("utf-8")
47+
48+
response = bedrock.invoke_model(
49+
modelId=os.environ.get("ANTHROPIC_MODEL"),
50+
body=body_bytes,
51+
)
52+
53+
response_body = json.loads(response["body"].read())
54+
55+
return response_body["content"][0]["text"]
56+
57+
1458
def main():
1559
parser = argparse.ArgumentParser(
1660
description="AI Code Reviewer for Patchwork",
@@ -62,6 +106,10 @@ def main():
62106
log(diff)
63107
log_end_sec()
64108

109+
log_open_sec(f"Patch Review")
110+
log(review_patch_with_bedrock(title, commit_msg, diff))
111+
log_end_sec()
112+
65113
log_end_sec()
66114

67115

0 commit comments

Comments
 (0)