From 58163e5129ef88f2f4fe0bfcbb5ea79eb2fad9f0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 09:50:48 +0200 Subject: [PATCH 1/7] improve usage guide --- pr_agent/servers/help.py | 83 +++++++++++++++++++++++++++ pr_agent/settings/configuration.toml | 1 + pr_agent/tools/pr_code_suggestions.py | 19 +++++- 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index fca19f97..d7a78e6e 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -231,3 +231,86 @@ Note that the tool does not have "memory" of previous questions, and answers eac output += f"\n\nSee the [ask usage](https://github.com/Codium-ai/pr-agent/blob/main/docs/ASK.md) page for a comprehensive guide on using this tool.\n\n" return output + + + @staticmethod + def get_improve_usage_guide(): + output = "**Overview:**\n" + output += "The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. " + output += "The tool can be triggered [automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools) every time a new PR is opened, or can be invoked manually by commenting on a PR.\n" + output += """\ +When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L69) related to the improve tool (`pr_code_suggestions` section), use the following template: + +``` +/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... +``` + +With a [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#working-with-github-app), use the following template: + +``` +[pr_code_suggestions] +some_config1=... +some_config2=... +``` + +""" + output += "\n\n" + + # automation + output += "\n\n" + + # extra instructions + output += "\n\n" + + # suggestions quality + output += "\n\n\n\n"\ + + # general + output += "\n\n\n\n" + + output += "
Enabling\\disabling automation
\n\n" + output += """\ +When you first install the app, the [default mode](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools) for the improve tool is: + +``` +pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...] +``` + +meaning the `improve` tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically. +""" + output += "\n\n
Utilizing extra instructions
\n\n" + output += '''\ +Extra instructions are very important for the `improve` tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project. + +Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on. + +Examples for extra instructions: + +``` +[pr_code_suggestions] # /improve # +extra_instructions=""" +Emphasize the following aspects: +- Does the code logic cover relevant edge cases? +- Is the code logic clear and easy to understand? +- Is the code logic efficient? +... +""" +``` + +Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable. + ''' + output += "\n\n
A note on code suggestions quality
\n\n" + output += """\ +- While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically. +- Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base. +- Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project. +- Best quality will be obtained by using 'improve --extended' mode. + +""" + output += "\n\n
More PR-Agent commands
\n\n" + output += HelpMessage.get_general_bot_help_text() + output += "\n\n
" + + output += f"\n\nSee the [improve usage](https://github.com/Codium-ai/pr-agent/blob/main/docs/IMPROVE.md) page for a more comprehensive guide on using this tool.\n\n" + + return output \ No newline at end of file diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index b0e9c295..5188ef4c 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -72,6 +72,7 @@ summarize = false include_improved_code = true extra_instructions = "" rank_suggestions = false +enable_help_text=true # params for '/improve --extended' mode auto_extended_mode=false num_code_suggestions_per_chunk=8 diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index ddc7913e..b89301c4 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -13,6 +13,7 @@ from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider from pr_agent.git_providers.git_provider import get_main_pr_language from pr_agent.log import get_logger +from pr_agent.servers.help import HelpMessage from pr_agent.tools.pr_description import insert_br_after_x_chars import difflib @@ -81,7 +82,18 @@ class PRCodeSuggestions: self.git_provider.remove_initial_comment() if get_settings().pr_code_suggestions.summarize: get_logger().info('Pushing summarize code suggestions...') - self.publish_summarizes_suggestions(data) + + # generate summarized suggestions + pr_body = self.generate_summarized_suggestions(data) + + # add usage guide + if self.git_provider.is_supported( + "gfm_markdown") and get_settings().pr_code_suggestions.enable_help_text: + pr_body += "
\n\n
✨ Usage guide:
\n\n" + pr_body += HelpMessage.get_improve_usage_guide() + pr_body += "\n
\n" + + self.git_provider.publish_comment(pr_body) else: get_logger().info('Pushing inline code suggestions...') self.push_inline_code_suggestions(data) @@ -298,7 +310,7 @@ class PRCodeSuggestions: return data_sorted - def publish_summarizes_suggestions(self, data: Dict): + def generate_summarized_suggestions(self, data: Dict) -> str: try: pr_body = "## PR Code Suggestions\n\n" @@ -379,6 +391,7 @@ class PRCodeSuggestions: # pr_body += "" pr_body += """""" pr_body += """""" - self.git_provider.publish_comment(pr_body) + return pr_body except Exception as e: get_logger().info(f"Failed to publish summarized code suggestions, error: {e}") + return "" From 298c41a100af661c168c103876474e0bfc501bab Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 10:03:48 +0200 Subject: [PATCH 2/7] improve usage guide --- docs/IMPROVE.md | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/docs/IMPROVE.md b/docs/IMPROVE.md index 698f88ef..bd94f52d 100644 --- a/docs/IMPROVE.md +++ b/docs/IMPROVE.md @@ -10,21 +10,24 @@ - [A note on code suggestions quality](#a-note-on-code-suggestions-quality) ## Overview -The `improve` tool scans the PR code changes, and automatically generates committable suggestions for improving the PR code. +The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is [opened](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools), or it can be invoked manually by commenting on any PR: ``` /improve ``` -For example: +The suggestions can appear as a collapsible comment (pr_code_suggestions.summarize=true): + - +Or as a separate commitable comment for each suggestion: ---- --- +Note that a collapsible comment has a significantly smaller PR footprint. + +### Extended mode An extended mode, which does not involve PR Compression and provides more comprehensive suggestions, can be invoked by commenting on any PR: ``` @@ -53,19 +56,6 @@ To edit [configurations](./../pr_agent/settings/configuration.toml#L66) related - `max_number_of_calls`: maximum number of chunks. Default is 5. - `final_clip_factor`: factor to remove suggestions with low confidence. Default is 0.9. -#### Summarize mode -In this mode, instead of presenting committable suggestions, the different suggestions will be combined into a single compact comment, with significantly smaller PR footprint. - -To invoke the summarize mode, use the following command: -``` -/improve --pr_code_suggestions.summarize=true -``` - -For example: - - - -___ ## Usage Tips @@ -87,10 +77,6 @@ Emphasize the following aspects: ``` Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable. -### PR footprint - regular vs summarize mode -The default mode of the `improve` tool provides committable suggestions. This mode as a high PR footprint, since each suggestion is a separate comment you need to resolve. -If you prefer something more compact, use the [`summarize`](#summarize-mode) mode, which combines all the suggestions into a single comment. - ### A note on code suggestions quality - While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically. From 7298548f826d636bed284af85af6afb081cfb573 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 10:06:27 +0200 Subject: [PATCH 3/7] improve usage guide --- docs/IMPROVE.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/IMPROVE.md b/docs/IMPROVE.md index bd94f52d..2d0f8751 100644 --- a/docs/IMPROVE.md +++ b/docs/IMPROVE.md @@ -16,16 +16,18 @@ The tool can be triggered automatically every time a new PR is [opened](https:// /improve ``` -The suggestions can appear as a collapsible comment (pr_code_suggestions.summarize=true): +### Summarized vs commitable code suggestions + +The code suggestions can appear as a single comment (`pr_code_suggestions.summarize=true`): -Or as a separate commitable comment for each suggestion: +Or as a separate commitable code comment for each suggestion: --- -Note that a collapsible comment has a significantly smaller PR footprint. +Note that a single comment has a significantly smaller PR footprint. We recommend this mode for most cases. ### Extended mode From 17ce2f0ed0b54b58b41dc696cc80a25d5af52985 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 10:09:44 +0200 Subject: [PATCH 4/7] improve usage guide --- docs/IMPROVE.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/IMPROVE.md b/docs/IMPROVE.md index 2d0f8751..1f60487f 100644 --- a/docs/IMPROVE.md +++ b/docs/IMPROVE.md @@ -19,11 +19,12 @@ The tool can be triggered automatically every time a new PR is [opened](https:// ### Summarized vs commitable code suggestions The code suggestions can appear as a single comment (`pr_code_suggestions.summarize=true`): +___ +___ Or as a separate commitable code comment for each suggestion: - - +___ --- @@ -50,7 +51,8 @@ To edit [configurations](./../pr_agent/settings/configuration.toml#L66) related - `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...". - `rank_suggestions`: if set to true, the tool will rank the suggestions, based on importance. Default is false. - `include_improved_code`: if set to true, the tool will include an improved code implementation in the suggestion. Default is true. - +- `summarize`: if set to true, the tool will display the suggestions in a single comment. Default is false. +- `enable_help_text`: if set to true, the tool will display a help text in the comment. Default is true. #### params for '/improve --extended' mode - `auto_extended_mode`: enable extended mode automatically (no need for the `--extended` option). Default is false. - `num_code_suggestions_per_chunk`: number of code suggestions provided by the 'improve' tool, per chunk. Default is 8. From e66bd7caa72b687e05dd5db1aed977c24d94c370 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 11:18:30 +0200 Subject: [PATCH 5/7] fallback to commitable --- pr_agent/tools/pr_code_suggestions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index b89301c4..9c54668a 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -80,15 +80,14 @@ class PRCodeSuggestions: if get_settings().config.publish_output: get_logger().info('Pushing PR code suggestions...') self.git_provider.remove_initial_comment() - if get_settings().pr_code_suggestions.summarize: + if get_settings().pr_code_suggestions.summarize and self.git_provider.is_supported("gfm_markdown"): get_logger().info('Pushing summarize code suggestions...') # generate summarized suggestions pr_body = self.generate_summarized_suggestions(data) # add usage guide - if self.git_provider.is_supported( - "gfm_markdown") and get_settings().pr_code_suggestions.enable_help_text: + if get_settings().pr_code_suggestions.enable_help_text: pr_body += "
\n\n
✨ Usage guide:
\n\n" pr_body += HelpMessage.get_improve_usage_guide() pr_body += "\n
\n" From 2132771f46c50b9883996bae82edd055c3a2cfe3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 11:29:50 +0200 Subject: [PATCH 6/7] s --- docs/IMPROVE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/IMPROVE.md b/docs/IMPROVE.md index 1f60487f..e8b11b84 100644 --- a/docs/IMPROVE.md +++ b/docs/IMPROVE.md @@ -18,7 +18,7 @@ The tool can be triggered automatically every time a new PR is [opened](https:// ### Summarized vs commitable code suggestions -The code suggestions can appear as a single comment (`pr_code_suggestions.summarize=true`): +The code suggestions can be presented as a single comment (`pr_code_suggestions.summarize=true`): ___ ___ From 8f510dc553065a7fd27faa16a18c0a4482f14aff Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 17 Jan 2024 11:47:59 +0200 Subject: [PATCH 7/7] s --- docs/IMPROVE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/IMPROVE.md b/docs/IMPROVE.md index e8b11b84..b9b389f0 100644 --- a/docs/IMPROVE.md +++ b/docs/IMPROVE.md @@ -18,7 +18,7 @@ The tool can be triggered automatically every time a new PR is [opened](https:// ### Summarized vs commitable code suggestions -The code suggestions can be presented as a single comment (`pr_code_suggestions.summarize=true`): +The code suggestions can be presented as a single comment (via `pr_code_suggestions.summarize=true`): ___ ___