From e53ae712f92d383e6758c3a0e2de369ced0bb931 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 6 Jul 2023 12:49:10 +0300 Subject: [PATCH] formatting --- pr_agent/algo/utils.py | 8 ++++++-- pr_agent/settings/pr_questions_prompts.toml | 1 + pr_agent/settings/pr_reviewer_prompts.toml | 4 ++-- pr_agent/tools/pr_questions.py | 4 +++- pr_agent/tools/pr_reviewer.py | 13 +++++++++++-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 33c16178..70994fd8 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -51,9 +51,13 @@ def parse_code_suggestion(code_suggestions: dict) -> str: markdown_text += f" - **{code_key}:**\n{code_str_indented}\n" else: if "suggestion number" in sub_key.lower(): - markdown_text += f"- **suggestion {sub_value}:**\n" # prettier formatting + # markdown_text += f"- **suggestion {sub_value}:**\n" # prettier formatting + pass + elif "relevant file" in sub_key.lower(): + markdown_text += f"\n - **{sub_key}:** {sub_value}\n" else: - markdown_text += f" - **{sub_key}:** {sub_value}\n" + markdown_text += f" **{sub_key}:** {sub_value}\n" + markdown_text += "\n" return markdown_text diff --git a/pr_agent/settings/pr_questions_prompts.toml b/pr_agent/settings/pr_questions_prompts.toml index e93b652b..55eb5cd7 100644 --- a/pr_agent/settings/pr_questions_prompts.toml +++ b/pr_agent/settings/pr_questions_prompts.toml @@ -3,6 +3,7 @@ system="""You are CodiumAI-PR-Reviewer, a language model designed to review git Your task is to answer questions about the new PR code (the '+' lines), and provide feedback. Be informative, constructive, and give examples. Try to be as specific as possible, and don't avoid answering the questions. Make sure not to repeat modifications already implemented in the new PR code (the '+' lines). +Answer only the questions, and don't add unrelated content. """ user="""PR Info: diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 42f753c3..3b3549f0 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -33,7 +33,7 @@ You must use the following JSON schema to format your answer: {%- if require_minimal_and_focused %} "Minimal and focused": { "type": "string", - "description": "is this PR as minimal and focused as possible, with all code changes centered around a single coherent theme, described in the PR description and title ?" explain your answer" + "description": "is this PR as minimal and focused as possible, with all code changes centered around a single coherent theme, described in the PR description and title ?" Make sure to explain your answer" } }, {%- endif %} @@ -107,7 +107,7 @@ Example output: "Relevant tests added": "No", {%- endif %} {%- if require_minimal_and_focused %} - "Minimal and focused": "No, because ..." + "Minimal and focused": "yes\\no, because ..." {%- endif %} }, "PR Feedback": diff --git a/pr_agent/tools/pr_questions.py b/pr_agent/tools/pr_questions.py index e83c4df6..7a6f791a 100644 --- a/pr_agent/tools/pr_questions.py +++ b/pr_agent/tools/pr_questions.py @@ -64,6 +64,8 @@ class PRQuestions: return response def _prepare_pr_answer(self) -> str: - answer_str = f"Questions: {self.question_str}\n\n" + answer_str = f"Question: {self.question_str}\n\n" answer_str += f"Answer: {self.prediction.strip()}\n\n" + if settings.config.verbosity_level >= 2: + logging.info(f"answer_str:\n{answer_str}") return answer_str diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 45bd75dc..4e2fbab3 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -81,9 +81,18 @@ class PRReviewer: except json.decoder.JSONDecodeError: logging.error("Unable to decode JSON response from AI") data = {} + + # reordering for nicer display + if 'PR Feedback' in data: + if 'Security concerns' in data['PR Feedback']: + val = data['PR Feedback']['Security concerns'] + del data['PR Feedback']['Security concerns'] + data['PR Analysis']['Security concerns'] = val + markdown_text = convert_to_markdown(data) - markdown_text += "\nAdd a comment that says 'Please review' to ask for a new review after you update the PR.\n" - markdown_text += "Add a comment that says 'Please answer ' to ask a question about this PR.\n" + markdown_text += "\n## How to use\n\n" + markdown_text += "```\nMention '@pr-agent' in a pr comment to get another review.\n" + markdown_text += "Mention '@pr-agent ' in a pr comment to ask a question about this PR.\n```\n" if settings.config.verbosity_level >= 2: logging.info(f"Markdown response:\n{markdown_text}") return markdown_text