From 6a268e17cd676f76b6bc26281dcba231cdb7ce6b Mon Sep 17 00:00:00 2001
From: binary-husky <505030475@qq.com>
Date: Sat, 29 Apr 2023 00:48:48 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=AC=E5=BC=8F=E9=87=8D?=
=?UTF-8?q?=E5=A4=8D=E6=98=BE=E7=A4=BA=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
request_llm/bridge_newbing.py | 5 ++++-
toolbox.py | 6 +++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/request_llm/bridge_newbing.py b/request_llm/bridge_newbing.py
index 0c48752..66db8b6 100644
--- a/request_llm/bridge_newbing.py
+++ b/request_llm/bridge_newbing.py
@@ -15,6 +15,7 @@ load_message = "等待NewBing响应。"
import time
import json
import re
+import logging
import asyncio
import importlib
import threading
@@ -26,7 +27,7 @@ def preprocess_newbing_out(s):
sub = lambda m: '\['+m.group(1)+'\]' # 将匹配到的数字作为替换值
result = re.sub(pattern, sub, s) # 替换操作
if '[1]' in result:
- result += '\n\n```\n' + "\n".join([r for r in result.split('\n') if r.startswith('[')]) + '\n```\n'
+ result += '\n\n
\n\n' + "\n\n".join(['`'+r+'`' for r in result.split('\n') if r.startswith('[')])
return result
def preprocess_newbing_out_simple(result):
@@ -247,5 +248,7 @@ def predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history=[], system_promp
yield from update_ui(chatbot=chatbot, history=history, msg="NewBing响应缓慢,尚未完成全部响应,请耐心完成后再提交新问题。")
if response == "[Local Message]: 等待NewBing响应中 ...": response = "[Local Message]: NewBing响应异常,请刷新界面重试 ..."
history.extend([inputs, response])
+ logging.info(f'[raw_input] {inputs}')
+ logging.info(f'[response] {response}')
yield from update_ui(chatbot=chatbot, history=history, msg="完成全部响应,请提交新问题。")
diff --git a/toolbox.py b/toolbox.py
index 565a87b..af28e8d 100644
--- a/toolbox.py
+++ b/toolbox.py
@@ -217,13 +217,17 @@ def text_divide_paragraph(text):
text = "".join(lines)
return text
-
+@lru_cache(maxsize=128) # 使用 lru缓存 加快转换速度
def markdown_convertion(txt):
"""
将Markdown格式的文本转换为HTML格式。如果包含数学公式,则先将公式转换为HTML格式。
"""
pre = ''
suf = '
'
+ if txt.startswith(pre) and txt.endswith(suf):
+ # print('警告,输入了已经经过转化的字符串,二次转化可能出问题')
+ return txt # 已经被转化过,不需要再次转化
+
markdown_extension_configs = {
'mdx_math': {
'enable_dollar_delimiter': True,