From 9c6aabb0bb8f2005bfc1afb2a2a72344dc970dd0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 9 Jan 2024 22:09:48 +0200 Subject: [PATCH 1/5] feat: Add custom labels and extra instructions sections to help.py, summarize mode to pr_code_suggestions.py, and summarize mode condition to pr_code_suggestions_prompts.toml --- pr_agent/servers/help.py | 20 +++++++++++++++++++ .../settings/pr_code_suggestions_prompts.toml | 3 +++ pr_agent/tools/pr_code_suggestions.py | 1 + 3 files changed, 24 insertions(+) diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index d1ece194..60ba285b 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -156,6 +156,7 @@ Note that when markers are enabled, if the original PR description does not cont """ output += "\n\n\n\n" + # custom labels output += "
Custom labels
\n\n" output += """\ The default labels of the `describe` tool are quite generic: [`Bug fix`, `Tests`, `Enhancement`, `Documentation`, `Other`]. @@ -174,6 +175,25 @@ Make sure to provide proper title, and a detailed and well-phrased description f """ output += "\n\n
\n\n" + # extra instructions + output += "
Utilizing extra instructions
\n\n" + output += '''\ + The `describe` tool can be configured with extra instructions, which can be used to guide the model to a produce a description with the relevant content or style. + + Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Notice that the general structure of the description is already defined by the tool, and cannot be changed. + What you can change is the content content or style of each sub-section of the description. + + Examples for extra instructions: + ``` + [pr_description] + extra_instructions=""" + - the title section should be in the following format: : + - ... + """ + ``` + Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable. + ''' + # general output += "\n\n
More PR-Agent commands
\n\n" output += HelpMessage.get_general_bot_help_text() diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index 418212b3..c1847931 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -39,6 +39,9 @@ Specific instructions: - Provide the exact line numbers range (inclusive) for each suggestion. - Assume there is additional relevant code, that is not included in the diff. - When quoting variables or names from the code, use backticks (`) instead of single quote ('). +{%- if summarize_mode %} +- If needed, use abbreviations for the 'existing code' and 'improved code' snippets, to keep the output short. +{%- endif %} {%- if extra_instructions %} diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 776b660f..b4f7a973 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -45,6 +45,7 @@ class PRCodeSuggestions: "language": self.main_language, "diff": "", # empty diff for initial calculation "num_code_suggestions": num_code_suggestions, + "summarize_mode": get_settings().pr_code_suggestions.summarize, "extra_instructions": get_settings().pr_code_suggestions.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), } From 2b607dbd9a99ef73ebbf4538065a55c50d10a731 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 9 Jan 2024 22:32:09 +0200 Subject: [PATCH 2/5] feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml --- .../settings/pr_code_suggestions_prompts.toml | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index c1847931..f2bef46c 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -6,16 +6,15 @@ Example for the PR Diff format: ====== ## src/file1.py -@@ -12,3 +12,4 @@ def func1(): +@@ ... @@ def func1(): __new hunk__ 12 code line1 that remained unchanged in the PR -14 +new code line1 added in the PR -15 +new code line2 added in the PR -16 code line2 that remained unchanged in the PR +13 +new code line2 added in the PR +14 code line3 that remained unchanged in the PR __old hunk__ code line1 that remained unchanged in the PR --code line that was removed in the PR - code line2 that remained unchanged in the PR +-old code line2 that was removed in the PR + code line3 that remained unchanged in the PR @@ ... @@ def func2(): @@ -31,13 +30,12 @@ __old hunk__ Specific instructions: -- Provide up to {{ num_code_suggestions }} code suggestions. Try to provide diverse and insightful suggestions. -- Prioritize suggestions that address major problems, issues and bugs in the code. As a second priority, suggestions should focus on enhancement, best practice, performance, maintainability, and other aspects. -- Don't suggest to add docstring, type hints, or comments. -- Suggestions should refer only to code from the '__new hunk__' sections, and focus on new lines of code (lines starting with '+'). +- Provide up to {{ num_code_suggestions }} code suggestions. The suggestions should be diverse and insightful. +- The suggestions should refer only to code from the '__new hunk__' sections, and focus on new lines of code (lines starting with '+'). +- Prioritize suggestions that address major problems, issues and bugs in the PR code. As a second priority, suggestions should focus on enhancement, best practice, performance, maintainability, and other aspects. +- Don't suggest to add docstring, type hints, or comments, or to remove unused imports. - Avoid making suggestions that have already been implemented in the PR code. For example, if you want to add logs, or change a variable to const, or anything else, make sure it isn't already in the '__new hunk__' code. - Provide the exact line numbers range (inclusive) for each suggestion. -- Assume there is additional relevant code, that is not included in the diff. - When quoting variables or names from the code, use backticks (`) instead of single quote ('). {%- if summarize_mode %} - If needed, use abbreviations for the 'existing code' and 'improved code' snippets, to keep the output short. @@ -57,10 +55,15 @@ The output must be a YAML object equivalent to type PRCodeSuggestions, according class CodeSuggestion(BaseModel): relevant_file: str = Field(description="the relevant file full path") suggestion_content: str = Field(description="an actionable suggestion for meaningfully improving the new code introduced in the PR") - existing_code: str = Field(description="a code snippet, showing the relevant code lines from a '__new hunk__' section. It must be contiguous, correctly formatted and indented, and without line numbers") +{%- if summarize_mode %} + existing_code: str = Field(description="a short code snippet from a '__new hunk__' section to illustrate the relevant existing code. Don't show the line numbers. Shorten parts of the code ('...') if needed") + improved_code: str = Field(description="a short code snippet to illustrate the improved code, after applying the suggestion. Shorten parts of the code ('...') if needed") +{%- else %} + existing_code: str = Field(description="a code snippet, demonstrating the relevant code lines from a '__new hunk__' section. It must be contiguous, correctly formatted and indented, and without line numbers") + improved_code: str = Field(description="a new code snippet, that can be used to replace the relevant lines in '__new hunk__' code. Replacement suggestions should be complete, correctly formatted and indented, and without line numbers") +{%- endif %} relevant_lines_start: int = Field(description="The relevant line number, from a '__new hunk__' section, where the suggestion starts (inclusive). Should be derived from the hunk line numbers, and correspond to the 'existing code' snippet above") relevant_lines_end: int = Field(description="The relevant line number, from a '__new hunk__' section, where the suggestion ends (inclusive). Should be derived from the hunk line numbers, and correspond to the 'existing code' snippet above") - improved_code: str = Field(description="a new code snippet, that can be used to replace the relevant lines in '__new hunk__' code. Replacement suggestions should be complete, correctly formatted and indented, and without line numbers") label: str = Field(description="a single label for the suggestion, to help the user understand the suggestion type. For example: 'security', 'bug', 'performance', 'enhancement', 'possible issue', 'best practice', 'maintainability', etc. Other labels are also allowed") class PRCodeSuggestions(BaseModel): @@ -93,16 +96,6 @@ user="""PR Info: Title: '{{title}}' -Branch: '{{branch}}' - -{%- if description %} - -Description: -====== -{{ description|trim }} -====== -{%- endif %} - {%- if language %} Main PR language: '{{ language }}' From fc502a6fd59c568c3d2d0a803cb790e460824ab6 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 9 Jan 2024 22:49:26 +0200 Subject: [PATCH 3/5] feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml --- pr_agent/servers/help.py | 27 ++++++++++--------- pr_agent/settings/pr_description_prompts.toml | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index 60ba285b..7b4f3ab8 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -178,21 +178,22 @@ Make sure to provide proper title, and a detailed and well-phrased description f # extra instructions output += "
Utilizing extra instructions
\n\n" output += '''\ - The `describe` tool can be configured with extra instructions, which can be used to guide the model to a produce a description with the relevant content or style. +The `describe` tool can be configured with extra instructions, to guide the model to a feedback tailored to the needs of your project. - Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Notice that the general structure of the description is already defined by the tool, and cannot be changed. - What you can change is the content content or style of each sub-section of the description. +Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Notice that the general structure of the description is fixed, and cannot be changed. Extra instructions can change the content or style of each sub-section of the PR description. + +Examples for extra instructions: +``` +[pr_description] +extra_instructions=""" +- the PR title should be in the format: ': ' +- ... +""" +``` +Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable. +''' + output += "\n\n
\n\n" - Examples for extra instructions: - ``` - [pr_description] - extra_instructions=""" - - the title section should be in the following format: : - - ... - """ - ``` - Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable. - ''' # general output += "\n\n
More PR-Agent commands
\n\n" diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 2b0664b9..09d1c6e4 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -15,7 +15,7 @@ Your task is to provide a full description for the PR content - files walkthroug Extra instructions from the user: ===== -{{ extra_instructions }} +{{extra_instructions}} ===== {% endif %} From 729b5d11c99b56f840c894b6a68e11ad1f3d8e0b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 9 Jan 2024 22:56:25 +0200 Subject: [PATCH 4/5] feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml --- pr_agent/servers/help.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pr_agent/servers/help.py b/pr_agent/servers/help.py index 7b4f3ab8..fca19f97 100644 --- a/pr_agent/servers/help.py +++ b/pr_agent/servers/help.py @@ -186,7 +186,8 @@ Examples for extra instructions: ``` [pr_description] extra_instructions=""" -- the PR title should be in the format: ': ' +- The PR title should be in the format: ': ' +- The title should be short and concise (up to 10 words) - ... """ ``` From 09ee0b64ba57d94d43f1eaaf9830301445065db0 Mon Sep 17 00:00:00 2001 From: mrT23 <tal.r@codium.ai> Date: Wed, 10 Jan 2024 09:37:05 +0200 Subject: [PATCH 5/5] feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml --- pr_agent/settings/pr_code_suggestions_prompts.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index f2bef46c..5aa3cce2 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -37,9 +37,6 @@ Specific instructions: - Avoid making suggestions that have already been implemented in the PR code. For example, if you want to add logs, or change a variable to const, or anything else, make sure it isn't already in the '__new hunk__' code. - Provide the exact line numbers range (inclusive) for each suggestion. - When quoting variables or names from the code, use backticks (`) instead of single quote ('). -{%- if summarize_mode %} -- If needed, use abbreviations for the 'existing code' and 'improved code' snippets, to keep the output short. -{%- endif %} {%- if extra_instructions %}