mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-06 13:50:44 +08:00
Merge remote-tracking branch 'origin/main' into tr/user_description
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.
|
||||||
|
@ -29,9 +29,10 @@ Under the section 'pr_reviewer', the [configuration file](./../pr_agent/settings
|
|||||||
- `remove_previous_review_comment`: if set to true, the tool will remove the previous review comment before adding a new one. Default is false.
|
- `remove_previous_review_comment`: if set to true, the tool will remove the previous review comment before adding a new one. Default is false.
|
||||||
- `persistent_comment`: if set to true, the review comment will be persistent, meaning that every new review request will edit the previous one. Default is true.
|
- `persistent_comment`: if set to true, the review comment will be persistent, meaning that every new review request will edit the previous one. Default is true.
|
||||||
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
|
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
|
||||||
#### SOC2 compliance 💎
|
#### SOC2 ticket compliance 💎
|
||||||
- `require_soc2_review`: if set to true, the tool will add a section that checks if the PR description includes a link to a ticket in a project management system (e.g., Jira, Asana, Trello, etc.), as required by SOC2 compliance. Default is false.
|
This sub-tool checks if the PR description properly contains a ticket to a project management system (e.g., Jira, Asana, Trello, etc.), as required by SOC2 compliance. If not, it will add a label to the PR: "Missing SOC2 ticket".
|
||||||
- `soc2_ticket_prompt`: The prompt to be used for the SOC2 ticket review. Default is "Does the PR description include a link to ticket in a project management system (e.g., Jira, Asana, Trello, etc.) ?". Edit this field if your compliance requirements are different.
|
- `require_soc2_review`: If set to true, the SOC2 ticket checker sub-tool will be enabled. Default is false.
|
||||||
|
- `soc2_ticket_prompt`: The prompt for the SOC2 ticket review. Default is: `Does the PR description include a link to ticket in a project management system (e.g., Jira, Asana, Trello, etc.) ?`. Edit this field if your compliance requirements are different.
|
||||||
#### review labels
|
#### review labels
|
||||||
- `enable_review_labels_security`: if set to true, the tool will publish a 'possible security issue' label if it detects a security issue. Default is true.
|
- `enable_review_labels_security`: if set to true, the tool will publish a 'possible security issue' label if it detects a security issue. Default is true.
|
||||||
- `enable_review_labels_effort`: if set to true, the tool will publish a 'Review effort [1-5]: x' label. Default is false.
|
- `enable_review_labels_effort`: if set to true, the tool will publish a 'Review effort [1-5]: x' label. Default is false.
|
||||||
@ -64,7 +65,7 @@ By invoking:
|
|||||||
```
|
```
|
||||||
/reflect_and_review
|
/reflect_and_review
|
||||||
```
|
```
|
||||||
The tool will first ask the author questions about the PR, and will guide the review based on his answers.
|
The tool will first ask the author questions about the PR, and will guide the review based on their answers.
|
||||||
|
|
||||||
<kbd><img src=https://codium.ai/images/pr_agent/reflection_questions.png width="768"></kbd>
|
<kbd><img src=https://codium.ai/images/pr_agent/reflection_questions.png width="768"></kbd>
|
||||||
<kbd><img src=https://codium.ai/images/pr_agent/reflection_answers.png width="768"></kbd>
|
<kbd><img src=https://codium.ai/images/pr_agent/reflection_answers.png width="768"></kbd>
|
||||||
@ -75,7 +76,7 @@ The tool will first ask the author questions about the PR, and will guide the re
|
|||||||
|
|
||||||
- With current level of AI for code (GPT-4), mistakes can happen. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
|
- With current level of AI for code (GPT-4), mistakes can happen. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
|
||||||
|
|
||||||
- Suggestions are not meant to be [simplistic](./../pr_agent/settings/pr_reviewer_prompts.toml#L29). 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.
|
- Suggestions are not meant to be [simplistic](./../pr_agent/settings/pr_reviewer_prompts.toml#L29). Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use their 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.
|
- Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project.
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
try:
|
try:
|
||||||
from langchain.chat_models import ChatOpenAI
|
from langchain.chat_models import ChatOpenAI, AzureChatOpenAI
|
||||||
from langchain.schema import SystemMessage, HumanMessage
|
from langchain.schema import SystemMessage, HumanMessage
|
||||||
except: # we don't enforce langchain as a dependency, so if it's not installed, just move on
|
except: # we don't enforce langchain as a dependency, so if it's not installed, just move on
|
||||||
pass
|
pass
|
||||||
@ -9,23 +9,41 @@ from pr_agent.config_loader import get_settings
|
|||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
from openai.error import APIError, RateLimitError, Timeout, TryAgain
|
from openai.error import APIError, RateLimitError, Timeout, TryAgain
|
||||||
from retry import retry
|
from retry import retry
|
||||||
|
import functools
|
||||||
|
|
||||||
OPENAI_RETRIES = 5
|
OPENAI_RETRIES = 5
|
||||||
|
|
||||||
class LangChainOpenAIHandler(BaseAiHandler):
|
class LangChainOpenAIHandler(BaseAiHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Initialize OpenAIHandler specific attributes here
|
# Initialize OpenAIHandler specific attributes here
|
||||||
|
super().__init__()
|
||||||
|
self.azure = get_settings().get("OPENAI.API_TYPE", "").lower() == "azure"
|
||||||
try:
|
try:
|
||||||
super().__init__()
|
if self.azure:
|
||||||
self._chat = ChatOpenAI(openai_api_key=get_settings().openai.key)
|
# using a partial function so we can set the deployment_id later to support fallback_deployments
|
||||||
|
# but still need to access the other settings now so we can raise a proper exception if they're missing
|
||||||
|
self._chat = functools.partial(
|
||||||
|
lambda **kwargs: AzureChatOpenAI(**kwargs),
|
||||||
|
openai_api_key=get_settings().openai.key,
|
||||||
|
openai_api_base=get_settings().openai.api_base,
|
||||||
|
openai_api_version=get_settings().openai.api_version,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._chat = ChatOpenAI(openai_api_key=get_settings().openai.key)
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
raise ValueError("OpenAI key is required") from e
|
if getattr(e, "name"):
|
||||||
|
raise ValueError(f"OpenAI {e.name} is required") from e
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self):
|
def chat(self):
|
||||||
return self._chat
|
if self.azure:
|
||||||
|
# we must set the deployment_id only here (instead of the __init__ method) to support fallback_deployments
|
||||||
|
return self._chat(deployment_name=self.deployment_id)
|
||||||
|
else:
|
||||||
|
return self._chat
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def deployment_id(self):
|
def deployment_id(self):
|
||||||
|
@ -101,11 +101,6 @@ class LiteLLMAIHandler(BaseAiHandler):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
deployment_id = self.deployment_id
|
deployment_id = self.deployment_id
|
||||||
if get_settings().config.verbosity_level >= 2:
|
|
||||||
get_logger().debug(
|
|
||||||
f"Generating completion with {model}"
|
|
||||||
f"{(' from deployment ' + deployment_id) if deployment_id else ''}"
|
|
||||||
)
|
|
||||||
if self.azure:
|
if self.azure:
|
||||||
model = 'azure/' + model
|
model = 'azure/' + model
|
||||||
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
|
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
|
||||||
|
@ -226,6 +226,11 @@ async def retry_with_fallback_models(f: Callable):
|
|||||||
# try each (model, deployment_id) pair until one is successful, otherwise raise exception
|
# try each (model, deployment_id) pair until one is successful, otherwise raise exception
|
||||||
for i, (model, deployment_id) in enumerate(zip(all_models, all_deployments)):
|
for i, (model, deployment_id) in enumerate(zip(all_models, all_deployments)):
|
||||||
try:
|
try:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
|
get_logger().debug(
|
||||||
|
f"Generating prediction with {model}"
|
||||||
|
f"{(' from deployment ' + deployment_id) if deployment_id else ''}"
|
||||||
|
)
|
||||||
get_settings().set("openai.deployment_id", deployment_id)
|
get_settings().set("openai.deployment_id", deployment_id)
|
||||||
return await f(model)
|
return await f(model)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -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,8 +281,14 @@ 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(
|
||||||
data_sorted = data_sorted[:new_len]
|
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]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if get_settings().config.verbosity_level >= 1:
|
if get_settings().config.verbosity_level >= 1:
|
||||||
get_logger().info(f"Could not sort suggestions, error: {e}")
|
get_logger().info(f"Could not sort suggestions, error: {e}")
|
||||||
|
@ -7,7 +7,7 @@ class PRConfig:
|
|||||||
"""
|
"""
|
||||||
The PRConfig class is responsible for listing all configuration options available for the user.
|
The PRConfig class is responsible for listing all configuration options available for the user.
|
||||||
"""
|
"""
|
||||||
def __init__(self, pr_url: str, args=None):
|
def __init__(self, pr_url: str, args=None, ai_handler=None):
|
||||||
"""
|
"""
|
||||||
Initialize the PRConfig object with the necessary attributes and objects to comment on a pull request.
|
Initialize the PRConfig object with the necessary attributes and objects to comment on a pull request.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user