From 42ae9c32122ea6c4fe84f80763b099fbf2b70190 Mon Sep 17 00:00:00 2001 From: yingying Date: Tue, 31 Dec 2024 15:08:49 +0800 Subject: [PATCH] fix: add the function to check if the pr summary is correct and fix it --- server/agent/prompts/pull_request.py | 16 +++++++++------- server/agent/tools/pull_request.py | 11 ++++++++++- server/core/models/bot.py | 1 - 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/agent/prompts/pull_request.py b/server/agent/prompts/pull_request.py index 5acc786e..f03a3833 100644 --- a/server/agent/prompts/pull_request.py +++ b/server/agent/prompts/pull_request.py @@ -26,15 +26,17 @@ ## Task 1: Summarize the Pull Request Using `create_pr_summary` tool to create PR summary. -Provider your response in markdown with the following content. follow the user's language. +Provider your response in markdown with the following content. - **Walkthrough**: A high-level summary of the overall change instead of specific files within 80 words. - **Changes**: A markdown table of files and their summaries. Group files with similar changes together into a single row to save space. +### Additional Instructions: +- Carefully check the markdown format. If there are any errors, fix them before providing the final result. +- Respond in the language of the PR title and content (e.g., if the title/content is in Chinese, reply in Chinese; if it's in English, reply in English). - At the end of the conversation, be sure to include the following wording and adhere to the language used in previous conversations: -
-🪧 Tips -For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me. -
+ +
🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.
+ ## Task 2: Code Review @@ -46,11 +48,11 @@ - Only the code diff is available for you to review, not the entire codebase. - Make comments only on code introducing clear and critical functional or security errors. - Do not comment on documentation, style, accuracy of text, or minor refactoring changes. -- Provide absolutely no feedback if no critical errors are found. - If necessary, provide code examples only for addressing critical errors. - Adhere to language-specific coding conventions used in the PR. - If there are critical errors to comment on, use the `create_review_comment` tool to create review comments. -- Skip the task if no errors are found. +- Avoid providing suggestions related to code optimization or best practices (e.g., "ensure" or "make sure") unless they address critical errors. +- Skip the task entirely if no critical errors are found in the code diff. - Upon completing the task, output strictly "All task finished", with no additional commentary. diff --git a/server/agent/tools/pull_request.py b/server/agent/tools/pull_request.py index dc8c4a04..b2a78e05 100644 --- a/server/agent/tools/pull_request.py +++ b/server/agent/tools/pull_request.py @@ -2,6 +2,7 @@ from typing import Optional from github import Github, Auth, ContentFile import json +import re from langchain.tools import tool from agent.tools.helper import need_github_login @@ -48,6 +49,10 @@ def get_file_content(repo_name: str, path: str, ref: Optional[str] = None): print(traceback.format_exception(e)) return json.dumps([]) + def fix_markdown_format(markdown_str: str) -> str: + fixed_str = re.sub(r"\\n", "\n", markdown_str) + return fixed_str + @tool def create_pr_summary(repo_name: str, pull_number: int, summary: str): """ @@ -62,7 +67,11 @@ def create_pr_summary(repo_name: str, pull_number: int, summary: str): g = Github(auth=token) repo = g.get_repo(repo_name) pull_request = repo.get_pull(pull_number) - pull_request.create_issue_comment(summary) + + # check if the summary is correct and fix it + format_summary = fix_markdown_format(summary) + print(f"summary:{format_summary}") + pull_request.create_issue_comment(format_summary) return json.dumps([]) @tool diff --git a/server/core/models/bot.py b/server/core/models/bot.py index c673c87e..c68597ff 100644 --- a/server/core/models/bot.py +++ b/server/core/models/bot.py @@ -19,7 +19,6 @@ class BotModel(BaseModel): temperature: Optional[float] = 0.2 n: Optional[int] = 1 top_p: Optional[float] = None - class RepoBindBotConfigVO(BaseModel):