fix: sanitize Ask tool answers to prevent markdown formatting issues with leading slashes

This commit is contained in:
mrT23
2024-12-30 16:54:03 +02:00
parent 014b1f20c5
commit 8463c4f549

View File

@ -120,6 +120,12 @@ class PRQuestions:
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"