From d98d0a291e34a3f05029210fe377499b0a6ceefa Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 23 Apr 2023 23:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=87=BD=E6=95=B0=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request_llm/bridge_newbing.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/request_llm/bridge_newbing.py b/request_llm/bridge_newbing.py index 79557ee..e65f6d0 100644 --- a/request_llm/bridge_newbing.py +++ b/request_llm/bridge_newbing.py @@ -21,6 +21,19 @@ import threading from toolbox import update_ui, get_conf, trimmed_format_exc from multiprocessing import Process, Pipe +def preprocess_newbing_out(s): + pattern = r'\^(\d+)\^' # 匹配^数字^ + 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' + return result + +def preprocess_newbing_out_simple(result): + if '[1]' in result: + result += '\n\n```\n' + "\n".join([r for r in result.split('\n') if r.startswith('[')]) + '\n```\n' + return result + class NewBingHandle(Process): def __init__(self): super().__init__(daemon=True) @@ -159,20 +172,6 @@ class NewBingHandle(Process): else: yield res # newbing回复的片段 self.threadLock.release() - - -def preprocess_newbing_out(s): - pattern = r'\^(\d+)\^' # 匹配^数字^ - 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' - return result - -def preprocess_newbing_out_simple(result): - if '[1]' in result: - result += '\n\n```\n' + "\n".join([r for r in result.split('\n') if r.startswith('[')]) + '\n```\n' - return result """