From 44155bcc24e83cb54e7f1482af21b6818d1a3f42 Mon Sep 17 00:00:00 2001 From: qingxu fu <505030475@qq.com> Date: Thu, 30 Mar 2023 12:52:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E6=89=BE=E8=AF=AD=E6=B3=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=B9=8B=E5=89=8D=E5=85=88=E6=B8=85=E9=99=A4=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functional.py | 6 ++++-- predict.py | 3 ++- toolbox.py | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/functional.py b/functional.py index d25e243..2ed1507 100644 --- a/functional.py +++ b/functional.py @@ -2,6 +2,7 @@ # 'secondary' 颜色对应 theme.py 中的 neutral_hue # 'stop' 颜色对应 theme.py 中的 color_er # 默认按钮颜色是 secondary +from toolbox import clear_line_break def get_functionals(): return { @@ -22,11 +23,12 @@ def get_functionals(): "查找语法错误": { "Prefix": r"Below is a paragraph from an academic paper. " + r"Can you help me ensure that the grammar and the spelling is correct? " + - r"If no mistake is found, tell me that this paragraph is good." + - r"If you find grammar mistakes,please list mistakes you find in a two-column markdown table, " + + r"Do not try to polish the text, if no mistake is found, tell me that this paragraph is good." + + r"If you find grammar or spelling mistakes, please list mistakes you find in a two-column markdown table, " + r"put the original text the first column, " + r"put the corrected text in the second column and highlight the key words you fixed." + "\n\n", "Suffix": r"", + "PreProcess": clear_line_break, # 预处理:清除换行符 }, "中译英": { "Prefix": r"Please translate following sentence to English:" + "\n\n", diff --git a/predict.py b/predict.py index 712cbd8..84036bc 100644 --- a/predict.py +++ b/predict.py @@ -119,8 +119,9 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt='' """ if additional_fn is not None: import functional - importlib.reload(functional) + importlib.reload(functional) # 热更新prompt functional = functional.get_functionals() + if "PreProcess" in functional[additional_fn]: inputs = functional[additional_fn]["PreProcess"](inputs) # 获取预处理函数(如果有的话) inputs = functional[additional_fn]["Prefix"] + inputs + functional[additional_fn]["Suffix"] if stream: diff --git a/toolbox.py b/toolbox.py index 544ffeb..d96b3f6 100644 --- a/toolbox.py +++ b/toolbox.py @@ -230,3 +230,9 @@ def get_conf(*args): assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)" return res + +def clear_line_break(txt): + txt = txt.replace('\n', ' ') + txt = txt.replace(' ', ' ') + txt = txt.replace(' ', ' ') + return txt \ No newline at end of file