Files
pr-agent/docs/IMPROVE.md

98 lines
4.9 KiB
Markdown
Raw Normal View History

2023-09-29 16:39:25 +03:00
# Improve Tool
2023-09-29 09:47:13 +03:00
2024-01-07 09:56:09 +02:00
## Table of Contents
- [Overview](#overview)
- [Configuration options](#configuration-options)
- [Usage Tips](#usage-tips)
- [Extra instructions](#extra-instructions)
- [PR footprint - regular vs summarize mode](#pr-footprint---regular-vs-summarize-mode)
- [A note on code suggestions quality](#a-note-on-code-suggestions-quality)
## Overview
2024-01-17 10:03:48 +02:00
The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code.
2024-01-07 09:56:09 +02:00
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:
2023-09-29 09:47:13 +03:00
```
/improve
```
2024-01-07 09:56:09 +02:00
2024-02-27 23:10:44 +02:00
### Summarized vs committable code suggestions
2024-01-17 10:06:27 +02:00
2024-01-17 11:47:59 +02:00
The code suggestions can be presented as a single comment (via `pr_code_suggestions.summarize=true`):
2024-01-17 10:09:44 +02:00
___
2024-01-17 10:03:48 +02:00
<kbd><img src=https://codium.ai/images/pr_agent/code_suggestions_as_comment.png width="768"></kbd>
2024-01-17 10:09:44 +02:00
___
2023-09-29 09:47:13 +03:00
2024-01-17 10:06:27 +02:00
Or as a separate commitable code comment for each suggestion:
2024-01-17 10:09:44 +02:00
___
<kbd><img src=https://codium.ai/images/pr_agent/improve.png width="768"></kbd>
2023-09-29 09:47:13 +03:00
2024-01-07 09:56:09 +02:00
---
2024-01-17 15:43:01 +02:00
Note that a single comment has a significantly smaller PR footprint. We recommend this mode for most cases.
Also note that collapsible are not supported in _Bitbucket_. Hence, the suggestions are presented there as code comments.
2024-01-17 10:03:48 +02:00
### Extended mode
2023-09-29 09:47:13 +03:00
An extended mode, which does not involve PR Compression and provides more comprehensive suggestions, can be invoked by commenting on any PR:
```
/improve --extended
```
2024-03-03 14:33:15 +02:00
or by setting:
```
[pr_code_suggestions]
auto_extended_mode=true
```
(True by default).
2024-01-07 09:56:09 +02:00
Note that the extended mode divides the PR code changes into chunks, up to the token limits, where each chunk is handled separately (might use multiple calls to GPT-4 for large PRs).
2023-11-26 17:41:20 +02:00
Hence, the total number of suggestions is proportional to the number of chunks, i.e., the size of the PR.
2023-09-29 09:47:13 +03:00
### Configuration options
2024-01-07 09:56:09 +02:00
To edit [configurations](./../pr_agent/settings/configuration.toml#L66) related to the improve tool (`pr_code_suggestions` section), use the following template:
```
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
```
2023-09-29 09:47:13 +03:00
2024-01-07 09:56:09 +02:00
#### General options
2023-09-29 09:47:13 +03:00
- `num_code_suggestions`: number of code suggestions provided by the 'improve' tool. Default is 4.
- `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.
2024-01-17 10:09:44 +02:00
- `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.
2023-09-29 09:47:13 +03:00
#### params for '/improve --extended' mode
2024-03-03 14:33:15 +02:00
- `auto_extended_mode`: enable extended mode automatically (no need for the `--extended` option). Default is true.
2023-09-29 09:47:13 +03:00
- `num_code_suggestions_per_chunk`: number of code suggestions provided by the 'improve' tool, per chunk. Default is 8.
- `rank_extended_suggestions`: if set to true, the tool will rank the suggestions, based on importance. Default is true.
- `max_number_of_calls`: maximum number of chunks. Default is 5.
2023-10-19 09:16:20 +03:00
- `final_clip_factor`: factor to remove suggestions with low confidence. Default is 0.9.
2023-11-30 16:35:44 +02:00
2024-01-07 09:56:09 +02:00
## Usage Tips
### Extra instructions
Extra instructions are very important for the `imrpove` tool, since they enable you 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:
2024-01-07 17:02:18 +02:00
- Does the code logic cover relevant edge cases?
2024-01-07 09:56:09 +02:00
- 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.
2023-11-30 16:35:44 +02:00
### A note on code suggestions quality
2023-10-19 09:16:20 +03:00
2023-11-30 17:13:47 +02:00
- 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.
2023-10-19 09:20:36 +03:00
- Suggestions are not meant to be [simplistic](./../pr_agent/settings/pr_code_suggestions_prompts.toml#L34). 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.
2024-02-29 17:20:15 +02:00
- Recommended to use the `exra_instructions` field to guide the model to suggestions that are more relevant to the specific needs of the project.
- Consider also trying the [Custom Suggestions Tool](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) 💎, that will **only** propose suggestions that follow specific guidelines defined by user.
2024-01-07 09:56:09 +02:00