From f7bef322125e80eb1a185c4b17e5a4310dbc5e3a Mon Sep 17 00:00:00 2001
From: Stalin Sabu Thomas <44336699+legendof-selda@users.noreply.github.com>
Date: Sun, 9 Feb 2025 14:49:20 +0530
Subject: [PATCH] fix(gradio): escape blocks in gradio chat
---
supermat/gradio/__init__.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/supermat/gradio/__init__.py b/supermat/gradio/__init__.py
index 81fca4d..91981ce 100644
--- a/supermat/gradio/__init__.py
+++ b/supermat/gradio/__init__.py
@@ -190,7 +190,9 @@ def chat(self, message: str, _history):
# history_langchain_format = self.convert_history_to_messages(history)
# history_langchain_format.append(HumanMessage(content=message))
gpt_response = self.chain.invoke(message)
- return gpt_response if isinstance(gpt_response, str) else gpt_response.content
+ gpt_response = gpt_response if isinstance(gpt_response, str) else gpt_response.content
+ gpt_response = re.sub(r"]*?/>", r"``\g<0>``", gpt_response)
+ return gpt_response
except Exception as e:
raise gr.Error(f"Error: {str(e)}\n{traceback.format_exc()}")