Merge pull request #5 from Codium-ai/enhancment/markdown

formatting
This commit is contained in:
Ori Kotek
2023-07-06 13:00:37 +03:00
committed by GitHub
5 changed files with 23 additions and 7 deletions

View File

@ -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

View File

@ -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:

View File

@ -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":

View File

@ -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

View File

@ -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 <QUESTION...>' 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 <QUESTION>' 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