From 47a2a3dd67b7b0e6619fd7d94d94937540f46336 Mon Sep 17 00:00:00 2001 From: Saurav Panda Date: Sat, 17 Aug 2024 01:07:12 -0700 Subject: [PATCH] feat updated pr review output format --- .experiments/code_review/main.py | 3 ++ config.json | 12 ++++++- kaizen/formatters/code_review_formatter.py | 41 ++++++++++++---------- kaizen/llms/prompts/code_review_prompts.py | 9 +++-- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/.experiments/code_review/main.py b/.experiments/code_review/main.py index 5cd44484..ef17342a 100644 --- a/.experiments/code_review/main.py +++ b/.experiments/code_review/main.py @@ -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") @@ -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) diff --git a/config.json b/config.json index 55916319..da96147e 100644 --- a/config.json +++ b/config.json @@ -11,7 +11,17 @@ "input_cost_per_token": 0.000000015, "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", + "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" } }, { diff --git a/kaizen/formatters/code_review_formatter.py b/kaizen/formatters/code_review_formatter.py index a2658cb7..bbe1cfb4 100644 --- a/kaizen/formatters/code_review_formatter.py +++ b/kaizen/formatters/code_review_formatter.py @@ -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 += "
\n" markdown_output += f"Click to expand ({len(other_issues)} issues)\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 += "
\n\n" @@ -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)) @@ -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 diff --git a/kaizen/llms/prompts/code_review_prompts.py b/kaizen/llms/prompts/code_review_prompts.py index 3c322ed5..f262ea06 100644 --- a/kaizen/llms/prompts/code_review_prompts.py +++ b/kaizen/llms/prompts/code_review_prompts.py @@ -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). @@ -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). @@ -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).