From 8463c4f5492f971008bb72e79785ab894775da38 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 30 Dec 2024 16:54:03 +0200 Subject: [PATCH] fix: sanitize Ask tool answers to prevent markdown formatting issues with leading slashes --- pr_agent/tools/pr_questions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pr_agent/tools/pr_questions.py b/pr_agent/tools/pr_questions.py index c6bb0accb..6f400b964 100644 --- a/pr_agent/tools/pr_questions.py +++ b/pr_agent/tools/pr_questions.py @@ -120,6 +120,12 @@ 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 /") + if model_answer_sanitized.startswith("/"): + model_answer_sanitized = " " + model_answer_sanitized + if model_answer_sanitized != model_answer: + get_logger().debug(f"Sanitized model answer", + artifact={"model_answer": model_answer, "sanitized_answer": model_answer_sanitized}) + answer_str = f"### **Ask**❓\n{self.question_str}\n\n" answer_str += f"### **Answer:**\n{model_answer_sanitized}\n\n"