From 16dc29a23a1c07ed0decacae278acb4ab0616f0f Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 30 Dec 2024 14:58:53 +0200 Subject: [PATCH 1/2] fix: sanitize Ask tool answers to prevent markdown formatting issues --- pr_agent/tools/pr_questions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_questions.py b/pr_agent/tools/pr_questions.py index 1ab496dc8..c6bb0accb 100644 --- a/pr_agent/tools/pr_questions.py +++ b/pr_agent/tools/pr_questions.py @@ -117,6 +117,10 @@ async def _get_prediction(self, model: str): return response def _prepare_pr_answer(self) -> str: + model_answer = self.prediction.strip() + # sanitize the answer so that no line will start with "/" + model_answer_sanitized = model_answer.replace("\n/", "\n /") + answer_str = f"### **Ask**❓\n{self.question_str}\n\n" - answer_str += f"### **Answer:**\n{self.prediction.strip()}\n\n" + answer_str += f"### **Answer:**\n{model_answer_sanitized}\n\n" return answer_str From 2f73ab6eab3a5cebce097e1680cf62f6d2ff759b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 30 Dec 2024 15:06:27 +0200 Subject: [PATCH 2/2] fix: sanitize Ask tool answers to prevent markdown formatting issues with leading slashes --- pr_agent/tools/pr_line_questions.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pr_agent/tools/pr_line_questions.py b/pr_agent/tools/pr_line_questions.py index 4ef5b9a7a..760c81ffa 100644 --- a/pr_agent/tools/pr_line_questions.py +++ b/pr_agent/tools/pr_line_questions.py @@ -79,13 +79,17 @@ async def run(self): line_end=line_end, side=side) if self.patch_with_lines: - response = await retry_with_fallback_models(self._get_prediction, model_type=ModelType.WEAK) + model_answer = await retry_with_fallback_models(self._get_prediction, model_type=ModelType.WEAK) + # sanitize the answer so that no line will start with "/" + model_answer_sanitized = model_answer.strip().replace("\n/", "\n /") + if model_answer_sanitized.startswith("/"): + model_answer_sanitized = " " + model_answer_sanitized get_logger().info('Preparing answer...') if comment_id: - self.git_provider.reply_to_comment_from_comment_id(comment_id, response) + self.git_provider.reply_to_comment_from_comment_id(comment_id, model_answer_sanitized) else: - self.git_provider.publish_comment(response) + self.git_provider.publish_comment(model_answer_sanitized) return ""