Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat updated pr review output format #446

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .experiments/code_review/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def process_pr(pr_url, reeval_response=False):
pull_request_files=pr_files,
user="kaizen/example",
reeval_response=reeval_response,
model="best"
)

# topics = clean_keys(review_data.topics, "important")
Expand Down Expand Up @@ -102,6 +103,8 @@ def main(pr_urls):
if __name__ == "__main__":
pr_urls = [
"https://github.com/Cloud-Code-AI/kaizen/pull/335",
"https://github.com/Cloud-Code-AI/kaizen/pull/440",
"https://github.com/Cloud-Code-AI/kaizen/pull/222"
# Add more PR URLs here
]
main(pr_urls)
12 changes: 11 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
"input_cost_per_token": 0.000000015,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: Changes made to sensitive file

Solution: NA

Reason For Comment: Changes were made to config.json, which needs review

sauravpanda marked this conversation as resolved.
Show resolved Hide resolved
"output_cost_per_token": 0.0000006,
"api_key": "os.environ/AZURE_API_KEY",
"api_base": "os.environ/AZURE_API_BASE"
"api_base": "os.environ/AZURE_API_BASE",
sauravpanda marked this conversation as resolved.
Show resolved Hide resolved
"base_model": "text-embedding-3-small"
},
"model_info": {
"max_tokens": 8191,
"max_input_tokens": 8191,
"output_vector_size": 1536,
"input_cost_per_token": 0.00000002,
"output_cost_per_token": 0.000000,
"litellm_provider": "openai",
"mode": "embedding"
}
},
{
Expand Down
41 changes: 23 additions & 18 deletions kaizen/formatters/code_review_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,38 @@ def create_pr_review_text(
("important", "🟠"),
]:
issues = categories[confidence]
if issues:
if issues and confidence == "critical":
markdown_output += f"## {emoji} {confidence.capitalize()} Issues\n\n"
markdown_output += create_issues_section(issues)
elif issues:
markdown_output += f"## {emoji} Refinement Suggestions:\n"
markdown_output += "These are not critical issues, but addressing them could further improve the code:\n\n"
markdown_output += create_issues_section(issues)

# Add other issues section (collapsible)
other_issues = categories["moderate"] + categories["low"] + categories["trivial"]
if other_issues:
markdown_output += "## 📌 Other Issues\n\n"
markdown_output += "## 📝 Minor Notes\nAdditional small points that you might want to consider:\n\n"
markdown_output += "<details>\n"
markdown_output += f"<summary><strong>Click to expand ({len(other_issues)} issues)</strong></summary>\n\n"

# Moderate issues
moderate_issues = categories["moderate"]
if moderate_issues:
markdown_output += "### ℹ️ Moderate Issues\n\n"
# markdown_output += "### ℹ️ Moderate Issues\n\n"
markdown_output += create_issues_section(moderate_issues)

# Low issues
low_issues = categories["low"]
if low_issues:
markdown_output += "### 📉 Low Priority Issues\n\n"
markdown_output += create_issues_section(low_issues)
# # Low issues
# low_issues = categories["low"]
# if low_issues:
# # markdown_output += "### 📉 Low Priority Issues\n\n"
# markdown_output += create_issues_section(low_issues)

# Trivial issues
trivial_issues = categories["trivial"]
if trivial_issues:
markdown_output += "### 🔎 Trivial Issues\n\n"
markdown_output += create_issues_section(trivial_issues)
# # Trivial issues
# trivial_issues = categories["trivial"]
# if trivial_issues:
# markdown_output += "### 🔎 Trivial Issues\n\n"
# markdown_output += create_issues_section(trivial_issues)

markdown_output += "</details>\n\n"

Expand All @@ -92,7 +96,7 @@ def create_stats_section(reviews: List[Dict]) -> str:
1 for review in reviews if review["confidence"] == "important"
)
minor_issues = sum(
1 for review in reviews if review["confidence"] not in ["critical", "important"]
1 for review in reviews if review["confidence"] in ["moderate"]
)
files_affected = len(set(review["file_name"] for review in reviews))

Expand Down Expand Up @@ -120,10 +124,11 @@ def create_issue_section(issue: Dict, index: int) -> str:
output += f"⚖️ **Severity:** {issue['severity_level']}/10\n"
output += f"🔍 **Description:** {issue['reason']}\n"
output += f"💡 **Solution:** {issue['solution']}\n\n"
output += "**Current Code:**\n"
output += f"```python\n{issue['actual_code']}\n```\n\n"
output += "**Suggested Code:**\n"
output += f"```python\n{issue['fixed_code']}\n```\n\n"
if issue.get('actual_code', None) or issue.get('fixed_code', ''):
output += "**Current Code:**\n"
output += f"```python\n{issue.get('actual_code', '')}\n```\n\n"
output += "**Suggested Code:**\n"
output += f"```python\n{issue.get('fixed_code', '')}\n```\n\n"
return output


Expand Down
9 changes: 6 additions & 3 deletions kaizen/llms/prompts/code_review_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
5. For 'fixed_code' -> always suggest changes for Additions.
## Field Guidelines:
- "fixed_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest doesnt has `0:[.]`.
- "fixed_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest does not has `0:[.]`.
- "actual_code": Current Code line which you think has error. make sure it always done on `+1:[+]` lines. If not, keep it empty ''.
- "start_line" and "end_line": Actual line numbers in the additions.
- "severity_level": 1 (least severe) to 10 (most critical).
Expand Down Expand Up @@ -137,7 +138,8 @@
5. For 'fixed_code' -> always suggest changes for Additions.
## Field Guidelines:
- "fixed_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest doesnt has `0:[.]`.
- "fixed_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest does not has `0:[.]`.
- "actual_code": Current Code line which you think has error. make sure it always done on `+1:[+]` lines. If not, keep it empty ''.
- "start_line" and "end_line": Actual line numbers in the additions.
- "severity_level": 1 (least severe) to 10 (most critical).
Expand Down Expand Up @@ -211,7 +213,8 @@
5. For 'fixed_code' -> always suggest changes for Additions.
## Field Guidelines:
- "fixed_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest doesnt has `0:[.]`.
- "fixed_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest does not has `0:[.]`.
- "actual_code": Current Code line which you think has error. make sure it always done on `+1:[+]` lines. If not, keep it empty ''.
- "start_line" and "end_line": Actual line numbers in the additions.
- "severity_level": 1 (least severe) to 10 (most critical).
Expand Down
Loading