qingxu99 commited on
Commit
44155bc
1 Parent(s): 4d02ea9

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

Browse files
Files changed (3) hide show
  1. functional.py +4 -2
  2. predict.py +2 -1
  3. toolbox.py +6 -0
functional.py CHANGED
@@ -2,6 +2,7 @@
2
  # 'secondary' 颜色对应 theme.py 中的 neutral_hue
3
  # 'stop' 颜色对应 theme.py 中的 color_er
4
  # 默认按钮颜色是 secondary
 
5
 
6
  def get_functionals():
7
  return {
@@ -22,11 +23,12 @@ def get_functionals():
22
  "查找语法错误": {
23
  "Prefix": r"Below is a paragraph from an academic paper. " +
24
  r"Can you help me ensure that the grammar and the spelling is correct? " +
25
- r"If no mistake is found, tell me that this paragraph is good." +
26
- r"If you find grammar mistakes,please list mistakes you find in a two-column markdown table, " +
27
  r"put the original text the first column, " +
28
  r"put the corrected text in the second column and highlight the key words you fixed." + "\n\n",
29
  "Suffix": r"",
 
30
  },
31
  "中译英": {
32
  "Prefix": r"Please translate following sentence to English:" + "\n\n",
 
2
  # 'secondary' 颜色对应 theme.py 中的 neutral_hue
3
  # 'stop' 颜色对应 theme.py 中的 color_er
4
  # 默认按钮颜色是 secondary
5
+ from toolbox import clear_line_break
6
 
7
  def get_functionals():
8
  return {
 
23
  "查找语法错误": {
24
  "Prefix": r"Below is a paragraph from an academic paper. " +
25
  r"Can you help me ensure that the grammar and the spelling is correct? " +
26
+ r"Do not try to polish the text, if no mistake is found, tell me that this paragraph is good." +
27
+ r"If you find grammar or spelling mistakes, please list mistakes you find in a two-column markdown table, " +
28
  r"put the original text the first column, " +
29
  r"put the corrected text in the second column and highlight the key words you fixed." + "\n\n",
30
  "Suffix": r"",
31
+ "PreProcess": clear_line_break, # 预处理:清除换行符
32
  },
33
  "中译英": {
34
  "Prefix": r"Please translate following sentence to English:" + "\n\n",
predict.py CHANGED
@@ -119,8 +119,9 @@ def predict(inputs, top_p, temperature, chatbot=[], history=[], system_prompt=''
119
  """
120
  if additional_fn is not None:
121
  import functional
122
- importlib.reload(functional)
123
  functional = functional.get_functionals()
 
124
  inputs = functional[additional_fn]["Prefix"] + inputs + functional[additional_fn]["Suffix"]
125
 
126
  if stream:
 
119
  """
120
  if additional_fn is not None:
121
  import functional
122
+ importlib.reload(functional) # 热更新prompt
123
  functional = functional.get_functionals()
124
+ if "PreProcess" in functional[additional_fn]: inputs = functional[additional_fn]["PreProcess"](inputs) # 获取预处理函数(如果有的话)
125
  inputs = functional[additional_fn]["Prefix"] + inputs + functional[additional_fn]["Suffix"]
126
 
127
  if stream:
toolbox.py CHANGED
@@ -230,3 +230,9 @@ def get_conf(*args):
230
  assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
231
  "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
232
  return res
 
 
 
 
 
 
 
230
  assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
231
  "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
232
  return res
233
+
234
+ def clear_line_break(txt):
235
+ txt = txt.replace('\n', ' ')
236
+ txt = txt.replace(' ', ' ')
237
+ txt = txt.replace(' ', ' ')
238
+ return txt