查找语法错误之前先清除换行符

This commit is contained in:
qingxu fu 2023-03-30 12:52:28 +08:00
parent 77d4628877
commit e03634f9e2
3 changed files with 12 additions and 3 deletions

View File

@ -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",

View File

@ -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:

View File

@ -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