From a74fca7b7d123bd6c2da2dfbb622fe856888c3c1 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Wed, 8 Jan 2025 17:42:07 +0200 Subject: [PATCH] fix: refine code suggestions prompts and avoid package-related comments --- pr_agent/settings/pr_code_suggestions_prompts.toml | 13 ++++++++----- pr_agent/tools/pr_code_suggestions.py | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index 7a449fb25..a3b62aab5 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -53,13 +53,13 @@ Specific guidelines for generating code suggestions: - Focus solely on enhancing new code introduced in the PR, identified by '+' prefixes in '__new hunk__' sections. {%- if not focus_only_on_problems %} - Prioritize suggestions that address potential issues, critical problems, and bugs in the PR code. Avoid repeating changes already implemented in the PR. If no pertinent suggestions are applicable, return an empty list. +- Don't suggest to add docstring, type hints, or comments, to remove unused imports, or to use more specific exception types. {%- else %} - Only give suggestions that address critical problems and bugs in the PR code. If no relevant suggestions are applicable, return an empty list. +- Do not suggest to change packages versions. {%- endif %} -- Don't suggest to add docstring, type hints, or comments, to remove unused imports, or to use more specific exception types. -- When referencing variables or names from the code, enclose them in backticks (`). Example: "ensure that `variable_name` is..." -- Be mindful you are viewing a partial PR code diff, not the full codebase. Avoid suggestions that might conflict with unseen code or alerting variables not declared in the visible scope, as the context is incomplete. - +- When mentioning code elements (variables, names, or files) in your response, surround them with backticks (`). For example: "verify that `user_id` is..." +- Remember that Pull Request reviews show only changed code segments (diff hunks), not the entire codebase. Without full context, be cautious about suggesting modifications that could duplicate existing functionality (such as error handling) or questioning variable declarations that may exist elsewhere. Keep your review focused on the visible changes, acknowledging they're part of a larger codebase. {%- if extra_instructions %} @@ -111,7 +111,6 @@ code_suggestions: ... ``` - Each YAML output MUST be after a newline, indented, with block scalar indicator ('|'). """ @@ -119,6 +118,10 @@ user="""--PR Info-- Title: '{{title}}' +{%- if date %} + +Today's Date: {{date}} +{%- endif %} The PR Diff: ====== diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index aebe5dec9..53ee10c85 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -4,6 +4,7 @@ import re import textwrap import traceback +from datetime import datetime from functools import partial from typing import Dict, List @@ -81,6 +82,7 @@ def __init__(self, pr_url: str, cli_mode=False, args: list = None, "relevant_best_practices": "", "is_ai_metadata": get_settings().get("config.enable_ai_metadata", False), "focus_only_on_problems": get_settings().get("pr_code_suggestions.focus_only_on_problems", False), + "date": datetime.now().strftime('%Y-%m-%d'), 'duplicate_prompt_examples': get_settings().config.get('duplicate_prompt_examples', False), } self.pr_code_suggestions_prompt_system = get_settings().pr_code_suggestions_prompt.system