Spaces:
Runtime error
Runtime error
Jia Xinglong
commited on
Commit
·
0b03c79
1
Parent(s):
a88a427
使用 re 模块的 match 函数可以更精准的匹配和确认 API_KEY 是否正确
Browse files- toolbox.py +9 -3
toolbox.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import markdown, mdtex2html, threading, importlib, traceback
|
| 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 |
"""
|
|
@@ -226,9 +227,14 @@ def get_conf(*args):
|
|
| 226 |
except: r = getattr(importlib.import_module('config'), arg)
|
| 227 |
res.append(r)
|
| 228 |
# 在读取API_KEY时,检查一下是不是忘了改config
|
| 229 |
-
if arg=='API_KEY'
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
return res
|
| 233 |
|
| 234 |
def clear_line_break(txt):
|
|
|
|
| 1 |
import markdown, mdtex2html, threading, importlib, traceback
|
| 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 |
"""
|
|
|
|
| 227 |
except: r = getattr(importlib.import_module('config'), arg)
|
| 228 |
res.append(r)
|
| 229 |
# 在读取API_KEY时,检查一下是不是忘了改config
|
| 230 |
+
if arg=='API_KEY':
|
| 231 |
+
# 正确的 API_KEY 是 "sk-" + 48 位大小写字母数字的组合
|
| 232 |
+
API_MATCH = re.match(r"sk-[a-zA-Z0-9]{48}$", r)
|
| 233 |
+
if API_MATCH:
|
| 234 |
+
print("您的 API_KEY 是: ", r, "\nAPI_KEY 导入成功")
|
| 235 |
+
else:
|
| 236 |
+
assert False, "正确的 API_KEY 是 'sk-' + '48 位大小写字母数字' 的组合,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
|
| 237 |
+
"(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
|
| 238 |
return res
|
| 239 |
|
| 240 |
def clear_line_break(txt):
|