Skip to content

Commit

Permalink
Merge pull request #494 from Cloud-Code-AI/493-feat-update-code-quali…
Browse files Browse the repository at this point in the history
…ty-prediction

feat: updated the code review prompt and added usage for retriever
  • Loading branch information
sauravpanda authored Aug 30, 2024
2 parents bd0923b + 2d45df6 commit 4dc6b98
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 28 deletions.
26 changes: 15 additions & 11 deletions .experiments/code_review/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ def compare_issues(ground_truth, model_issues):
description_similarity = calculate_similarity(
gt_issue["description"], model_issue["description"]
)
# actual_code_similarity = calculate_similarity(
# gt_issue.get("current_code",''), model_issue.get("current_code", '')
# )
if (
description_similarity > 0.1
description_similarity > 0.25
and gt_issue["file_path"] == model_issue["file_path"]
and abs(
int(gt_issue.get("start_line", 0))
- int(model_issue.get("start_line", -10))
)
<= 1
and abs(
int(gt_issue.get("end_line", 0))
- int(model_issue.get("end_line", -10))
)
<= 1
# and actual_code_similarity > 0.5
# and abs(
# int(gt_issue.get("start_line", 0))
# - int(model_issue.get("start_line", -10))
# )
# <= 1
# and abs(
# int(gt_issue.get("end_line", 0))
# - int(model_issue.get("end_line", -10))
# )
# <= 1
and abs(
int(gt_issue.get("severity", 0))
- int(model_issue.get("severity", -10))
Expand Down
Empty file removed kaizen/helpers/chunker.py
Empty file.
26 changes: 20 additions & 6 deletions kaizen/helpers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ def patch_to_separate_chunks(patch_text):
return "\n".join(output)


def format_change(old_num, new_num, change_type, content):
old_num_str = f"{old_num:<4}" if old_num is not None else " "
new_num_str = f"{new_num:<4}" if new_num is not None else " "
def format_change(old_num, new_num, change_type, content, ignore_deletions=False):
old_num_str = f"{old_num:<5}" if old_num is not None else "_ "
new_num_str = f"{new_num:<5}" if new_num is not None else "_ "
if ignore_deletions:
old_num_str = "_ "
return f"{old_num_str} {new_num_str} {change_type} {content}"


Expand Down Expand Up @@ -235,19 +237,31 @@ def patch_to_combined_chunks(patch_text, ignore_deletions=False):
elif line.startswith("-"):
content = line[1:]
if not ignore_deletions:
changes.append(format_change(removal_line_num, None, "-1:[-]", content))
changes.append(
format_change(
removal_line_num, None, "-1:[-]", content, ignore_deletions
)
)
removal_line_num += 1
unedited_removal_num = removal_line_num
elif line.startswith("+"):
content = line[1:]
changes.append(format_change(None, addition_line_num, "+1:[+]", content))
changes.append(
format_change(
None, addition_line_num, "+1:[+]", content, ignore_deletions
)
)
addition_line_num += 1
unedited_addition_num = addition_line_num
else:
content = line
changes.append(
format_change(
unedited_removal_num, unedited_addition_num, " 0:[.]", content
unedited_removal_num,
unedited_addition_num,
" 0:[.]",
content,
ignore_deletions,
)
)
unedited_removal_num += 1
Expand Down
39 changes: 29 additions & 10 deletions kaizen/llms/prompts/code_review_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
]
}}
## Code Quality Percentage Guidelines:
- Consider the following factors when calculating the final percentage:
- Code readability and maintainability
- Adherence to best practices and coding standards
- Presence of comments and documentation
- Efficient use of resources
- Proper error handling and edge case consideration
- Adjust the final percentage based on overall code quality assessment
- Ensure the final percentage is between 0 and 100
## Guidelines:
- Provide specific feedback with file paths and line numbers
- Use markdown for code snippets. Make sure all code is following the original indentations.
Expand Down Expand Up @@ -56,7 +66,6 @@
4. A new line 'result += y' was added, incorporating the new parameter.
5. The return statement remained unchanged.
## Review Focus:
1. Removals (-1:[-]): Identify if removal causes problems in remaining code. Remember any line having -1:[-] is removed line from the new code.
2. Additions (+1:[+]): Provide detailed feedback and suggest improvements. Remember any line having +1:[+] is added line.
Expand All @@ -65,10 +74,10 @@
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 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 ''.
- "suggested_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest does not has `0:[.]`.
- "current_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).
- "severity": 1 (least severe) to 10 (most critical).
Prioritize issues based on their potential impact on code quality, functionality, and maintainability. Provide concrete examples or code snippets when suggesting improvements.
## PATCH DATA:
Expand Down Expand Up @@ -97,6 +106,15 @@
]
}}
## Code Quality Percentage Guidelines:
- Consider the following factors when calculating the final percentage:
- Code readability and maintainability
- Adherence to best practices and coding standards
- Presence of comments and documentation
- Efficient use of resources
- Proper error handling and edge case consideration
- Adjust the final percentage based on overall code quality assessment
- Ensure the final percentage is between 0 and 100
## Guidelines:
- Provide specific feedback with file paths and line numbers
Expand Down Expand Up @@ -129,20 +147,21 @@
3. The line 'result = x * 2' remained unchanged.
4. A new line 'result += y' was added, incorporating the new parameter.
5. The return statement remained unchanged.
6. First number is line number of old file. Second number is line number of new filee
## Review Focus:
1. Removals (-1:[-]): Identify if removal causes problems in remaining code. Remember any line having -1:[-] is removed line from the new code.
2. Additions (+1:[+]): Provide detailed feedback and suggest improvements. Remember any line having +1:[+] is added line.
3. Consider impact of changes on overall code structure and functionality.
4. Note unchanged lines (0:[.]) for context.
5. For 'fixed_code' -> always suggest changes for Additions.
5. For 'suggested_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 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 ''.
- "suggested_code": Corrected code for additions only, between start_line and end_line. make sure start_line you suggest does not has `0:[.]`.
- "current_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).
- "severity": 1 (least severe) to 10 (most critical).
Prioritize issues based on their potential impact on code quality, functionality, and maintainability. Provide concrete examples or code snippets when suggesting improvements.
Expand Down Expand Up @@ -213,10 +232,10 @@
2. Additions (+1:[+]): Provide detailed feedback and suggest improvements. Remember any line having +1:[+] is added line.
3. Consider impact of changes on overall code structure and functionality.
4. Note unchanged lines (0:[.]) for context.
5. For 'fixed_code' -> always suggest changes for Additions.
5. For 'suggested_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 does not has `0:[.]`.
- "suggested_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
2 changes: 1 addition & 1 deletion kaizen/tests/helpers/test_patch_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,4 @@ def _process_file_chunk(
+"""
'''

print(patch_to_combined_chunks(patch_text=patch_data2))
print(patch_to_combined_chunks(patch_text=patch_data2, ignore_deletions=True))

0 comments on commit 4dc6b98

Please sign in to comment.