From 400146985a6ef66b7fe466e5dfea20a98207c15b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 5 Feb 2025 09:31:32 +0200 Subject: [PATCH 1/2] feat: improve code suggestions table with impact levels and styling --- pr_agent/tools/pr_code_suggestions.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 53ee10c8..b64b2a43 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -720,7 +720,7 @@ class PRCodeSuggestions: header = f"Suggestion" delta = 66 header += "  " * delta - pr_body += f"""Category{header}Score""" + pr_body += f"""Category{header}Impact""" pr_body += """""" suggestions_labels = dict() # add all suggestions related to each label @@ -740,7 +740,7 @@ class PRCodeSuggestions: counter_suggestions = 0 for label, suggestions in suggestions_labels.items(): num_suggestions = len(suggestions) - pr_body += f"""{label.capitalize()}\n""" + pr_body += f"""{label.capitalize()}\n""" for i, suggestion in enumerate(suggestions): relevant_file = suggestion['relevant_file'].strip() @@ -795,13 +795,17 @@ class PRCodeSuggestions: {example_code.rstrip()} """ pr_body += f"
Suggestion importance[1-10]: {suggestion['score']}\n\n" - pr_body += f"Why: {suggestion['score_why']}\n\n" + pr_body += f"__\n\nWhy: {suggestion['score_why']}\n\n" pr_body += f"
" pr_body += f"" # # add another column for 'score' - pr_body += f"{suggestion['score']}\n\n" + score_int = int(suggestion['score']) + score_str = f"{score_int}" + if get_settings().pr_code_suggestions.new_score_mechanism: + score_str = self.get_score_str(score_int) + pr_body += f"{score_str}\n\n" pr_body += f"" counter_suggestions += 1 @@ -814,6 +818,14 @@ class PRCodeSuggestions: get_logger().info(f"Failed to publish summarized code suggestions, error: {e}") return "" + def get_score_str(self, score: int) -> str: + if score >= 9: + return "High" + elif score >= 7: + return "Medium" + else: # score < 7 + return "Low" + async def self_reflect_on_suggestions(self, suggestion_list: List, patches_diff: str, From 69f19f1abd85a1f0a4c0d42074cb2f5245f2c4f0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 5 Feb 2025 09:41:01 +0200 Subject: [PATCH 2/2] feat: improve code suggestions impact levels with configurable thresholds --- pr_agent/settings/configuration.toml | 3 +++ pr_agent/tools/pr_code_suggestions.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 62649d5e..01c09207 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -121,6 +121,9 @@ max_history_len=4 apply_suggestions_checkbox=true # suggestions scoring suggestions_score_threshold=0 # [0-10]| recommend not to set this value above 8, since above it may clip highly relevant suggestions +new_score_mechanism=true +new_score_mechanism_th_high=9 +new_score_mechanism_th_medium=7 # params for '/improve --extended' mode auto_extended_mode=true num_code_suggestions_per_chunk=4 diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index b64b2a43..5a98cc9e 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -794,14 +794,15 @@ class PRCodeSuggestions: {example_code.rstrip()} """ - pr_body += f"
Suggestion importance[1-10]: {suggestion['score']}\n\n" - pr_body += f"__\n\nWhy: {suggestion['score_why']}\n\n" - pr_body += f"
" + if suggestion.get('score_why'): + pr_body += f"
Suggestion importance[1-10]: {suggestion['score']}\n\n" + pr_body += f"__\n\nWhy: {suggestion['score_why']}\n\n" + pr_body += f"
" pr_body += f"" # # add another column for 'score' - score_int = int(suggestion['score']) + score_int = int(suggestion.get('score', 0)) score_str = f"{score_int}" if get_settings().pr_code_suggestions.new_score_mechanism: score_str = self.get_score_str(score_int) @@ -819,9 +820,11 @@ class PRCodeSuggestions: return "" def get_score_str(self, score: int) -> str: - if score >= 9: + th_high = get_settings().pr_code_suggestions.get('new_score_mechanism_th_high', 9) + th_medium = get_settings().pr_code_suggestions.get('new_score_mechanism_th_medium', 7) + if score >= th_high: return "High" - elif score >= 7: + elif score >= th_medium: return "Medium" else: # score < 7 return "Low"