Your Name commited on
Commit
a3952be
2 Parent(s): fa7464a e5cc1ea

Merge branch 'dev' of github.com:binary-husky/chatgpt_academic into dev

Browse files
Files changed (1) hide show
  1. toolbox.py +9 -3
toolbox.py CHANGED
@@ -1,6 +1,7 @@
1
  import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect
2
  from show_math import convert as convert_math
3
  from functools import wraps
 
4
 
5
  def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[], sys_prompt=''):
6
  """
@@ -237,9 +238,14 @@ def get_conf(*args):
237
  except: r = getattr(importlib.import_module('config'), arg)
238
  res.append(r)
239
  # 在读取API_KEY时,检查一下是不是忘了改config
240
- if arg=='API_KEY' and len(r) != 51:
241
- assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
242
- "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
 
 
 
 
 
243
  return res
244
 
245
  def clear_line_break(txt):
 
1
  import markdown, mdtex2html, threading, importlib, traceback, importlib, inspect
2
  from show_math import convert as convert_math
3
  from functools import wraps
4
+ import re
5
 
6
  def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temperature, history=[], sys_prompt=''):
7
  """
 
238
  except: r = getattr(importlib.import_module('config'), arg)
239
  res.append(r)
240
  # 在读取API_KEY时,检查一下是不是忘了改config
241
+ if arg=='API_KEY':
242
+ # 正确的 API_KEY "sk-" + 48 位大小写字母数字的组合
243
+ API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r)
244
+ if API_MATCH:
245
+ print("您的 API_KEY 是: ", r, "\nAPI_KEY 导入成功")
246
+ else:
247
+ assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
248
+ "(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
249
  return res
250
 
251
  def clear_line_break(txt):