From e70b63651359f94f181e7870572f368e87903035 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Sat, 9 Sep 2023 17:50:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E5=AD=A6=E5=85=AC?= =?UTF-8?q?=E5=BC=8F=E5=88=A4=E5=AE=9A=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- toolbox.py | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/toolbox.py b/toolbox.py index 273ecee..ab8d046 100644 --- a/toolbox.py +++ b/toolbox.py @@ -281,8 +281,7 @@ def report_execption(chatbot, history, a, b): 向chatbot中添加错误信息 """ chatbot.append((a, b)) - history.append(a) - history.append(b) + history.extend([a, b]) def text_divide_paragraph(text): @@ -305,6 +304,7 @@ def text_divide_paragraph(text): text = "
".join(lines) return pre + text + suf + @lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度 def markdown_convertion(txt): """ @@ -359,19 +359,41 @@ def markdown_convertion(txt): content = content.replace('\n', '') return content - def no_code(txt): - if '```' not in txt: - return True - else: - if '```reference' in txt: return True # newbing - else: return False + def is_equation(txt): + """ + 判定是否为公式 | 测试1 写出洛伦兹定律,使用tex格式公式 测试2 给出柯西不等式,使用latex格式 测试3 写出麦克斯韦方程组 + """ + if '```' in txt and '```reference' not in txt: return False + if '$' not in txt and '\\[' not in txt: return False + mathpatterns = { + r'(?