mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 12:50:38 +08:00
Merge pull request #569 from zmeir/zmeir/enhance/auto_improve_extended_simple
Add toggle to automatically enable `/improve --extended`
This commit is contained in:
@ -29,6 +29,7 @@ Under the section 'pr_code_suggestions', the [configuration file](./../pr_agent/
|
|||||||
- `include_improved_code`: if set to true, the tool will include an improved code implementation in the suggestion. Default is true.
|
- `include_improved_code`: if set to true, the tool will include an improved code implementation in the suggestion. Default is true.
|
||||||
|
|
||||||
#### params for '/improve --extended' mode
|
#### 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.
|
- `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.
|
- `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.
|
- `max_number_of_calls`: maximum number of chunks. Default is 5.
|
||||||
|
@ -70,6 +70,7 @@ include_improved_code = true
|
|||||||
extra_instructions = ""
|
extra_instructions = ""
|
||||||
rank_suggestions = false
|
rank_suggestions = false
|
||||||
# params for '/improve --extended' mode
|
# params for '/improve --extended' mode
|
||||||
|
auto_extended_mode=false
|
||||||
num_code_suggestions_per_chunk=8
|
num_code_suggestions_per_chunk=8
|
||||||
rank_extended_suggestions = true
|
rank_extended_suggestions = true
|
||||||
max_number_of_calls = 5
|
max_number_of_calls = 5
|
||||||
|
@ -26,7 +26,7 @@ class PRCodeSuggestions:
|
|||||||
|
|
||||||
# extended mode
|
# extended mode
|
||||||
try:
|
try:
|
||||||
self.is_extended = any(["extended" in arg for arg in args])
|
self.is_extended = self._get_is_extended(args or [])
|
||||||
except:
|
except:
|
||||||
self.is_extended = False
|
self.is_extended = False
|
||||||
if self.is_extended:
|
if self.is_extended:
|
||||||
@ -206,6 +206,16 @@ class PRCodeSuggestions:
|
|||||||
|
|
||||||
return new_code_snippet
|
return new_code_snippet
|
||||||
|
|
||||||
|
def _get_is_extended(self, args: list[str]) -> bool:
|
||||||
|
"""Check if extended mode should be enabled by the `--extended` flag or automatically according to the configuration"""
|
||||||
|
if any(["extended" in arg for arg in args]):
|
||||||
|
get_logger().info("Extended mode is enabled by the `--extended` flag")
|
||||||
|
return True
|
||||||
|
if get_settings().pr_code_suggestions.auto_extended_mode:
|
||||||
|
get_logger().info("Extended mode is enabled automatically based on the configuration toggle")
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
async def _prepare_prediction_extended(self, model: str) -> dict:
|
async def _prepare_prediction_extended(self, model: str) -> dict:
|
||||||
get_logger().info('Getting PR diff...')
|
get_logger().info('Getting PR diff...')
|
||||||
patches_diff_list = get_pr_multi_diffs(self.git_provider, self.token_handler, model,
|
patches_diff_list = get_pr_multi_diffs(self.git_provider, self.token_handler, model,
|
||||||
@ -271,7 +281,13 @@ class PRCodeSuggestions:
|
|||||||
data_sorted[importance_order - 1] = suggestion_list[suggestion_number - 1]
|
data_sorted[importance_order - 1] = suggestion_list[suggestion_number - 1]
|
||||||
|
|
||||||
if get_settings().pr_code_suggestions.final_clip_factor != 1:
|
if get_settings().pr_code_suggestions.final_clip_factor != 1:
|
||||||
new_len = int(0.5 + len(data_sorted) * get_settings().pr_code_suggestions.final_clip_factor)
|
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)
|
||||||
|
if new_len < len(data_sorted):
|
||||||
data_sorted = data_sorted[:new_len]
|
data_sorted = data_sorted[:new_len]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if get_settings().config.verbosity_level >= 1:
|
if get_settings().config.verbosity_level >= 1:
|
||||||
|
Reference in New Issue
Block a user