Skip to content

Commit

Permalink
Merge pull request #1426 from Codium-ai/tr/ask_fix
Browse files Browse the repository at this point in the history
fix: sanitize Ask tool answers to prevent markdown formatting issues
  • Loading branch information
mrT23 authored Dec 30, 2024
2 parents bd95220 + 2f73ab6 commit 014b1f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pr_agent/tools/pr_line_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down
6 changes: 5 additions & 1 deletion pr_agent/tools/pr_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 014b1f2

Please sign in to comment.