-
Notifications
You must be signed in to change notification settings - Fork 739
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
Enhancements in Token Clipping, PR Statistics Calculation, and Conditional Review Labeling #848
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -575,7 +575,7 @@ def clip_tokens(text: str, max_tokens: int, add_three_dots=True) -> str: | |||||||||
num_output_chars = int(chars_per_token * max_tokens) | ||||||||||
clipped_text = text[:num_output_chars] | ||||||||||
if add_three_dots: | ||||||||||
clipped_text += " ...(truncated)" | ||||||||||
clipped_text += "\n...(truncated)" | ||||||||||
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. Suggestion: Consider removing the newline character before the truncation message to maintain the consistency of the text format, especially if the text is expected to be in a single line or paragraph format. [enhancement]
Suggested change
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. Consider handling cases where the input text ends with a newline character. Appending "\n...(truncated)" directly might result in two newline characters in a row, which could be unintended. A simple check to see if 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. Suggestion: Consider removing the newline character before the truncation message to maintain the consistency of the text output format. [enhancement]
Suggested change
|
||||||||||
return clipped_text | ||||||||||
except Exception as e: | ||||||||||
get_logger().warning(f"Failed to clip tokens: {e}") | ||||||||||
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. Suggestion: When catching a broad exception in the
Suggested change
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -745,22 +745,4 @@ def auto_approve(self) -> bool: | |||||||||||||||||||||
return False | ||||||||||||||||||||||
|
||||||||||||||||||||||
def calc_pr_statistics(self, pull_request_data: dict): | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
out = {} | ||||||||||||||||||||||
from datetime import datetime | ||||||||||||||||||||||
created_at = pull_request_data['created_at'] | ||||||||||||||||||||||
closed_at = pull_request_data['closed_at'] | ||||||||||||||||||||||
closed_at_datetime = datetime.strptime(closed_at, "%Y-%m-%dT%H:%M:%SZ") | ||||||||||||||||||||||
created_at_datetime = datetime.strptime(created_at, "%Y-%m-%dT%H:%M:%SZ") | ||||||||||||||||||||||
difference = closed_at_datetime - created_at_datetime | ||||||||||||||||||||||
out['hours'] = difference.total_seconds() / 3600 | ||||||||||||||||||||||
out['commits'] = pull_request_data['commits'] | ||||||||||||||||||||||
out['comments'] = pull_request_data['comments'] | ||||||||||||||||||||||
out['review_comments'] = pull_request_data['review_comments'] | ||||||||||||||||||||||
out['changed_files'] = pull_request_data['changed_files'] | ||||||||||||||||||||||
out['additions'] = pull_request_data['additions'] | ||||||||||||||||||||||
out['deletions'] = pull_request_data['deletions'] | ||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||
get_logger().exception(f"Failed to calculate PR statistics, error: {e}") | ||||||||||||||||||||||
return {} | ||||||||||||||||||||||
return out | ||||||||||||||||||||||
return {} | ||||||||||||||||||||||
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. Suggestion: The new implementation of
Suggested change
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. While simplifying the 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. Suggestion: Replacing the detailed PR statistics calculation with an empty dictionary removes functionality. Consider implementing a simplified version of the statistics calculation or handling potential exceptions more gracefully to maintain this feature. [bug]
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -357,6 +357,9 @@ def _can_run_incremental_review(self) -> bool: | |||||||||||||||||||||
return True | ||||||||||||||||||||||
|
||||||||||||||||||||||
def set_review_labels(self, data): | ||||||||||||||||||||||
if not get_settings().config.publish_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. Ensure that the condition |
||||||||||||||||||||||
return | ||||||||||||||||||||||
Comment on lines
+360
to
+361
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. Suggestion: Adding a condition to check
Suggested change
Comment on lines
+360
to
+361
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. Suggestion: Adding a check for
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
if (get_settings().pr_reviewer.enable_review_labels_security or | ||||||||||||||||||||||
get_settings().pr_reviewer.enable_review_labels_effort): | ||||||||||||||||||||||
try: | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,5 +15,5 @@ def test_clip(self): | |||||||||
|
||||||||||
max_tokens = 10 | ||||||||||
result = clip_tokens(text, max_tokens) | ||||||||||
expected_results = 'line1\nline2\nline3\nli ...(truncated)' | ||||||||||
expected_results = 'line1\nline2\nline3\nli\n...(truncated)' | ||||||||||
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. Suggestion: The test expectation has been updated to match the new output of
Suggested change
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. Given the change in 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. Suggestion: The expected result in the test case should match the output format of the
Suggested change
|
||||||||||
assert result == expected_results |
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.
Changes walkthrough
utils.py (+1/-1)
Improve Text Token Clipping Presentation
pr_agent/algo/utils.py
clip_tokens
function to append a newline before"...(truncated)" when clipping text tokens.
github_provider.py (+1/-19)
Simplify PR Statistics Calculation
pr_agent/git_providers/github_provider.py
calc_pr_statistics
function, making itreturn an empty dictionary directly.
pr_reviewer.py (+3/-0)
Conditional Review Labeling Based on Configuration
pr_agent/tools/pr_reviewer.py
publish_output
setting before settingreview labels.
test_clip_tokens.py (+1/-1)
Update Test for Improved Token Clipping
tests/unittest/test_clip_tokens.py
clip_tokens
to reflect the new line additionbefore "...(truncated)".