-
Notifications
You must be signed in to change notification settings - Fork 315
adding the comment typing generation #5110
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
Open
olewicki
wants to merge
6
commits into
master
Choose a base branch
from
revcom_type
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
45be1f4
adding the typing generation
3f808b5
Update bugbug/tools/code_review.py
olewicki dda0699
Update bugbug/tools/code_review.py
olewicki de593e4
Update bugbug/tools/code_review.py
olewicki eae4a99
Update bugbug/tools/code_review.py
olewicki fe90105
label_justification to label_subcategory + shift get_comment_type to …
olewicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ class InlineComment: | |
is_generated: bool | None = None | ||
explanation: str | None = None | ||
order: int | None = None | ||
type: str | None = None | ||
type_justification: str | None = None | ||
|
||
|
||
class ModelResultError(Exception): | ||
|
@@ -326,6 +328,85 @@ class LargeDiffError(Exception): | |
""" | ||
|
||
|
||
PROMPT_TEMPLATE_LABELLING = """You are an expert in source code reviews. | ||
|
||
Your task is to review each comment in the "Review Comments List" and assign it one of the following five categories, along with a justification based on its subcategory. | ||
|
||
Categories and Subcategories | ||
1. Readability: | ||
Focus: Making the code easier to read and understand. | ||
Subcategories include: | ||
* Refactoring - Consistency: Uniform coding styles and practices. | ||
* Refactoring - Naming Convention: Clear, descriptive identifiers. | ||
* Refactoring - Readability: General clarity improvements. | ||
* Refactoring - Simplification: Reducing unnecessary complexity. | ||
* Refactoring - Visual Representation: Improving code layout and formatting. | ||
|
||
2. Design and Maintainability: | ||
Focus: Improving structure and long-term upkeep. | ||
Subcategories include: | ||
* Discussion - Design discussion: Architectural or structural decisions. | ||
* Functional - Support: Adding or enhancing support functionality. | ||
* Refactoring - Alternate Output: Changing what the code returns or prints. | ||
* Refactoring - Code Duplication: Removing repeated code. | ||
* Refactoring - Code Simplification: Streamlining logic. | ||
* Refactoring - Magic Numbers: Replacing hard-coded values with named constants. | ||
* Refactoring - Organization of the code: Logical structuring of code. | ||
* Refactoring - Solution approach: Rethinking problem-solving approaches. | ||
* Refactoring - Unused Variables: Removing variables not in use. | ||
* Refactoring - Variable Declarations: Improving how variables are declared or initialized. | ||
|
||
3. Performance: | ||
Focus: Making the code faster or more efficient. | ||
Subcategories include: | ||
* Functional - Performance: General performance improvements. | ||
* Functional - Performance Optimization: Specific performance-focused refactoring. | ||
* Functional - Performance and Safety: Balancing speed and reliability. | ||
* Functional - Resource: Efficient use of memory, CPU, etc. | ||
* Refactoring - Performance Optimization: Improving performance through code changes. | ||
|
||
4. Defect: | ||
Focus: Fixing bugs and potential issues. | ||
Subcategories include: | ||
* Functional - Conditional Compilation | ||
* Functional - Consistency and Thread Safety | ||
* Functional - Error Handling | ||
* Functional - Exception Handling | ||
* Functional - Initialization | ||
* Functional - Interface | ||
* Functional - Lambda Usage | ||
* Functional - Logical | ||
* Functional - Null Handling | ||
* Functional - Security | ||
* Functional - Serialization | ||
* Functional - Syntax | ||
* Functional - Timing | ||
* Functional - Type Safety | ||
* Functional - Validation | ||
|
||
5. Other: | ||
Use only if none of the above apply: | ||
Subcategories include: | ||
* None of the above | ||
* Does not apply | ||
|
||
Format: | ||
Use the following JSON format to label and justify each comment. Do not modify the comment content—only append the "label" and "label_justification" fields. | ||
[ | ||
{{ | ||
"file": "com/br/main/Pressure.java", | ||
"code_line": 458, | ||
"comment" : "In the third code block, you are using `nsAutoStringN<256>` instead of `nsString`. This is a good change as `nsAutoStringN<256>` is more efficient for small strings. However, you should ensure that the size of `tempString` does not exceed 256 characters, as `nsAutoStringN<256>` has a fixed size." | ||
"label": "Performance", | ||
"label_justification": "Functional - Performance Optimization: Specific performance-focused refactoring." | ||
}} | ||
] | ||
|
||
Review Comments List: | ||
{comments} | ||
""" | ||
|
||
|
||
class ReviewRequest: | ||
patch_id: str | ||
|
||
|
@@ -1122,6 +1203,10 @@ def generate_processed_output(output: str, patch: PatchSet) -> Iterable[InlineCo | |
on_removed_code=not scope["has_added_lines"], | ||
explanation=comment["explanation"], | ||
order=comment["order"], | ||
type=comment["type"] if "type" in comment else None, | ||
type_justification=comment["type_justification"] | ||
if "type_justification" in comment | ||
else None, | ||
olewicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
|
||
|
@@ -1202,6 +1287,12 @@ def __init__( | |
verbose=verbose, | ||
) | ||
|
||
self.com_type_labelling = LLMChain( | ||
olewicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prompt=PromptTemplate.from_template(PROMPT_TEMPLATE_LABELLING), | ||
llm=self.llm, | ||
verbose=verbose, | ||
) | ||
|
||
self.function_search = function_search | ||
|
||
self.review_comments_db = review_comments_db | ||
|
@@ -1350,6 +1441,30 @@ def _generate_suggestions(self, patch: Patch): | |
|
||
return output | ||
|
||
def _get_comment_type(self, comments): | ||
output = self.com_type_labelling.invoke( | ||
{ | ||
"comments": comments, | ||
}, | ||
return_only_outputs=True, | ||
)["text"] | ||
labelling = parse_model_output(output) | ||
dir_labels = { | ||
f"{lab['file']}{lab['code_line']}{lab['comment']}": { | ||
olewicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"type": lab["label"], | ||
"type_justification": lab["label_justification"], | ||
} | ||
for lab in labelling | ||
} | ||
|
||
for com in comments: | ||
if f"{com['file']}{com['code_line']}{com['comment']}" in dir_labels: | ||
com.update( | ||
dir_labels[f"{com['file']}{com['code_line']}{com['comment']}"] | ||
) | ||
olewicki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return json.dumps(comments) | ||
|
||
@retry(retry=retry_if_exception_type(ModelResultError), stop=stop_after_attempt(3)) | ||
def run(self, patch: Patch) -> list[InlineComment] | None: | ||
if self.count_tokens(patch.raw_diff) > 21000: | ||
|
@@ -1376,6 +1491,8 @@ def run(self, patch: Patch) -> list[InlineComment] | None: | |
return_only_outputs=True, | ||
)["text"] | ||
|
||
raw_output = self._get_comment_type(raw_output) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move the process after running |
||
|
||
if self.verbose: | ||
GenerativeModelTool._print_answer(raw_output) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a subcategory, not a justification.