From 0198c61cf79d3d4bc0deb941b08681485c282a03 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 22 Sep 2024 09:00:56 +0300 Subject: [PATCH 1/2] update docs --- docs/docs/tools/improve.md | 46 +++++++++++-------- .../docs/usage-guide/automations_and_usage.md | 4 +- pr_agent/settings/configuration.toml | 1 - pr_agent/tools/pr_code_suggestions.py | 7 +-- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/docs/docs/tools/improve.md b/docs/docs/tools/improve.md index 1ae903b38..ec63c1b4e 100644 --- a/docs/docs/tools/improve.md +++ b/docs/docs/tools/improve.md @@ -98,6 +98,28 @@ the tool can automatically approve the PR when the user checks the self-review c ![self_review_2](https://codium.ai/images/pr_agent/self_review_2.png){width=512} +### How many code suggestions are generated? +PR-Agent uses a dynamic strategy to generate code suggestions based on the size of the pull request (PR). Here's how it works: + +1. Chunking large PRs: + + - PR-Agent divides large PRs into 'chunks'. + - Each chunk contains up to `pr_code_suggestions.max_context_tokens` tokens (default: 14,000). + + +2. Generating suggestions: + + - For each chunk, PR-Agent generates up to `pr_code_suggestions.num_code_suggestions_per_chunk` suggestions (default: 4). + + +This approach has two main benefits: + +- Scalability: The number of suggestions scales with the PR size, rather than being fixed. +- Quality: By processing smaller chunks, the AI can maintain higher quality suggestions, as larger contexts tend to decrease AI performance. + +Note: Chunking is primarily relevant for large PRs. For most PRs (up to 500 lines of code), PR-Agent will be able to process the entire code in a single call. + + ### 'Extra instructions' and 'best practices' #### Extra instructions @@ -170,18 +192,10 @@ Using a combination of both can help the AI model to provide relevant and tailor ??? example "General options" - - - - - - - - @@ -212,28 +226,24 @@ Using a combination of both can help the AI model to provide relevant and tailor
num_code_suggestionsNumber of code suggestions provided by the 'improve' tool. Default is 4 for CLI, 0 for auto tools.
extra_instructions Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
rank_suggestionsIf set to true, the tool will rank the suggestions, based on importance. Default is false.
commitable_code_suggestions If set to true, the tool will display the suggestions as commitable code comments. Default is false.
-??? example "params for 'extended' mode" +??? example "Params for number of suggestions and AI calls" - + - - - - - + - + - - + +
auto_extended_modeEnable extended mode automatically (no need for the --extended option). Default is true.Enable chunking the PR code and running the tool on each chunk. Default is true.
num_code_suggestions_per_chunkNumber of code suggestions provided by the 'improve' tool, per chunk. Default is 5.
rank_extended_suggestionsIf set to true, the tool will rank the suggestions, based on importance. Default is true.Number of code suggestions provided by the 'improve' tool, per chunk. Default is 4.
max_number_of_callsMaximum number of chunks. Default is 5.Maximum number of chunks. Default is 3.
final_clip_factorFactor to remove suggestions with low confidence. Default is 0.9.rank_extended_suggestionsIf set to true, the tool will rank the suggestions, based on importance. Default is true.
diff --git a/docs/docs/usage-guide/automations_and_usage.md b/docs/docs/usage-guide/automations_and_usage.md index b3d92fcdf..0f780d80d 100644 --- a/docs/docs/usage-guide/automations_and_usage.md +++ b/docs/docs/usage-guide/automations_and_usage.md @@ -175,10 +175,10 @@ By uploading a local `.pr_agent.toml` file to the root of the repo's main branch For example, if your local `.pr_agent.toml` file contains: ``` [pr_reviewer] -inline_code_comments = true +extra_instructions = "Answer in japanese" ``` -Each time you invoke a `/review` tool, it will use inline code comments. +Each time you invoke a `/review` tool, it will use the extra instructions you set in the local configuration file. Note that among other limitations, BitBucket provides relatively low rate-limits for applications (up to 1000 requests per hour), and does not provide an API to track the actual rate-limit usage. diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 9655c95db..0ce19ca63 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -108,7 +108,6 @@ enable_help_text=false [pr_code_suggestions] # /improve # max_context_tokens=14000 -num_code_suggestions=4 commitable_code_suggestions = false extra_instructions = "" rank_suggestions = false diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 828d7d338..2d4cfea87 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -44,10 +44,8 @@ def __init__(self, pr_url: str, cli_mode=False, args: list = None, self.is_extended = self._get_is_extended(args or []) except: self.is_extended = False - if self.is_extended: - num_code_suggestions = get_settings().pr_code_suggestions.num_code_suggestions_per_chunk - else: - num_code_suggestions = get_settings().pr_code_suggestions.num_code_suggestions + num_code_suggestions = get_settings().pr_code_suggestions.num_code_suggestions_per_chunk + self.ai_handler = ai_handler() self.ai_handler.main_pr_language = self.main_language @@ -601,7 +599,6 @@ async def rank_suggestions(self, data: List) -> List: if get_settings().pr_code_suggestions.final_clip_factor != 1: max_len = max( len(data_sorted), - get_settings().pr_code_suggestions.num_code_suggestions, get_settings().pr_code_suggestions.num_code_suggestions_per_chunk, ) new_len = int(0.5 + max_len * get_settings().pr_code_suggestions.final_clip_factor) From 7e5ddf7e3779c7a2017486290e1d619dec088ea3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 22 Sep 2024 09:19:39 +0300 Subject: [PATCH 2/2] Update improve.md with enhanced self-review configuration details --- docs/docs/tools/improve.md | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/docs/tools/improve.md b/docs/docs/tools/improve.md index ec63c1b4e..c0ba56970 100644 --- a/docs/docs/tools/improve.md +++ b/docs/docs/tools/improve.md @@ -86,30 +86,39 @@ code_suggestions_self_review_text = "... (your text here) ..." ![self_review_1](https://codium.ai/images/pr_agent/self_review_1.png){width=512} -💎 In addition, by setting: -``` -[pr_code_suggestions] -approve_pr_on_self_review = true -``` -the tool can automatically approve the PR when the user checks the self-review checkbox. -!!! tip "Tip - demanding self-review from the PR author" - If you set the number of required reviewers for a PR to 2, this effectively means that the PR author must click the self-review checkbox before the PR can be merged (in addition to a human reviewer). + +!!! tip "Tip - demanding self-review from the PR author 💎" + + By setting: + ``` + [pr_code_suggestions] + approve_pr_on_self_review = true + ``` + the tool can automatically add an approval when the PR author clicks the self-review checkbox. + + + - If you set the number of required reviewers for a PR to 2, this effectively means that the PR author must click the self-review checkbox before the PR can be merged (in addition to a human reviewer). ![self_review_2](https://codium.ai/images/pr_agent/self_review_2.png){width=512} + - If you keep the number of required reviewers for a PR to 1 and enable this configuration, this effectively means that the PR author can approve the PR by actively clicking the self-review checkbox. + + To prevent unauthorized approvals, this configuration defaults to false, and cannot be altered through online comments; enabling requires a direct update to the configuration file and a commit to the repository. This ensures that utilizing the feature demands a deliberate documented decision by the repository owner. + + ### How many code suggestions are generated? PR-Agent uses a dynamic strategy to generate code suggestions based on the size of the pull request (PR). Here's how it works: -1. Chunking large PRs: +1) Chunking large PRs: - - PR-Agent divides large PRs into 'chunks'. - - Each chunk contains up to `pr_code_suggestions.max_context_tokens` tokens (default: 14,000). +- PR-Agent divides large PRs into 'chunks'. +- Each chunk contains up to `pr_code_suggestions.max_context_tokens` tokens (default: 14,000). -2. Generating suggestions: +2) Generating suggestions: - - For each chunk, PR-Agent generates up to `pr_code_suggestions.num_code_suggestions_per_chunk` suggestions (default: 4). +- For each chunk, PR-Agent generates up to `pr_code_suggestions.num_code_suggestions_per_chunk` suggestions (default: 4). This approach has two main benefits: