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'(?