Spaces:
Runtime error
Runtime error
修改配置的读取方式
Browse files- check_proxy.py +4 -3
- main.py +4 -3
- predict.py +5 -3
- toolbox.py +18 -6
check_proxy.py
CHANGED
@@ -21,6 +21,7 @@ def check_proxy(proxies):
|
|
21 |
|
22 |
if __name__ == '__main__':
|
23 |
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
24 |
-
|
25 |
-
|
26 |
-
check_proxy(proxies)
|
|
|
|
21 |
|
22 |
if __name__ == '__main__':
|
23 |
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
24 |
+
from toolbox import get_conf
|
25 |
+
proxies, = get_conf('proxies')
|
26 |
+
check_proxy(proxies)
|
27 |
+
|
main.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
2 |
import gradio as gr
|
3 |
from predict import predict
|
4 |
-
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated
|
5 |
|
6 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
11 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
|
|
1 |
import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
|
2 |
import gradio as gr
|
3 |
from predict import predict
|
4 |
+
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_conf
|
5 |
|
6 |
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
7 |
+
proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = \
|
8 |
+
get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION')
|
9 |
+
|
10 |
|
11 |
# 如果WEB_PORT是-1, 则随机选取WEB端口
|
12 |
PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
predict.py
CHANGED
@@ -20,10 +20,12 @@ import importlib
|
|
20 |
|
21 |
# config_private.py放自己的秘密如API和代理网址
|
22 |
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
-
timeout_bot_msg = '[
|
|
|
27 |
|
28 |
def get_full_error(chunk, stream_response):
|
29 |
"""
|
|
|
20 |
|
21 |
# config_private.py放自己的秘密如API和代理网址
|
22 |
# 读取时首先看是否存在私密的config_private配置文件(不受git管控),如果有,则覆盖原config文件
|
23 |
+
from toolbox import get_conf
|
24 |
+
proxies, API_URL, API_KEY, TIMEOUT_SECONDS, MAX_RETRY, LLM_MODEL = \
|
25 |
+
get_conf('proxies', 'API_URL', 'API_KEY', 'TIMEOUT_SECONDS', 'MAX_RETRY', 'LLM_MODEL')
|
26 |
|
27 |
+
timeout_bot_msg = '[Local Message] Request timeout. Network error. Please check proxy settings in config.py.' + \
|
28 |
+
'网络错误,检查代理服务器是否可用,以及代理设置的格式是否正确,格式须是[协议]://[地址]:[端口],缺一不可。'
|
29 |
|
30 |
def get_full_error(chunk, stream_response):
|
31 |
"""
|
toolbox.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import markdown, mdtex2html, threading
|
2 |
from show_math import convert as convert_math
|
3 |
from functools import wraps
|
4 |
|
@@ -7,9 +7,9 @@ def predict_no_ui_but_counting_down(i_say, i_say_show_user, chatbot, top_p, temp
|
|
7 |
调用简单的predict_no_ui接口,但是依然保留了些许界面心跳功能,当对话太长时,会自动采用二分法截断
|
8 |
"""
|
9 |
import time
|
10 |
-
try: from config_private import TIMEOUT_SECONDS, MAX_RETRY
|
11 |
-
except: from config import TIMEOUT_SECONDS, MAX_RETRY
|
12 |
from predict import predict_no_ui
|
|
|
|
|
13 |
# 多线程的时候,需要一个mutable结构在不同线程之间传递信息
|
14 |
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
15 |
mutable = [None, '']
|
@@ -80,10 +80,9 @@ def CatchException(f):
|
|
80 |
try:
|
81 |
yield from f(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT)
|
82 |
except Exception as e:
|
83 |
-
import traceback
|
84 |
from check_proxy import check_proxy
|
85 |
-
|
86 |
-
|
87 |
tb_str = regular_txt_to_markdown(traceback.format_exc())
|
88 |
chatbot[-1] = (chatbot[-1][0], f"[Local Message] 实验性函数调用出错: \n\n {tb_str} \n\n 当前代理可用性: \n\n {check_proxy(proxies)}")
|
89 |
yield chatbot, history, f'异常 {e}'
|
@@ -218,3 +217,16 @@ def on_report_generated(files, chatbot):
|
|
218 |
# files.extend(report_files)
|
219 |
chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧文件上传区,请查收。'])
|
220 |
return report_files, chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import markdown, mdtex2html, threading, importlib, traceback
|
2 |
from show_math import convert as convert_math
|
3 |
from functools import wraps
|
4 |
|
|
|
7 |
调用简单的predict_no_ui接口,但是依然保留了些许界面心跳功能,当对话太长时,会自动采用二分法截断
|
8 |
"""
|
9 |
import time
|
|
|
|
|
10 |
from predict import predict_no_ui
|
11 |
+
from toolbox import get_conf
|
12 |
+
TIMEOUT_SECONDS, MAX_RETRY = get_conf('TIMEOUT_SECONDS', 'MAX_RETRY')
|
13 |
# 多线程的时候,需要一个mutable结构在不同线程之间传递信息
|
14 |
# list就是最简单的mutable结构,我们第一个位置放gpt输出,第二个位置传递报错信息
|
15 |
mutable = [None, '']
|
|
|
80 |
try:
|
81 |
yield from f(txt, top_p, temperature, chatbot, history, systemPromptTxt, WEB_PORT)
|
82 |
except Exception as e:
|
|
|
83 |
from check_proxy import check_proxy
|
84 |
+
from toolbox import get_conf
|
85 |
+
proxies, = get_conf('proxies')
|
86 |
tb_str = regular_txt_to_markdown(traceback.format_exc())
|
87 |
chatbot[-1] = (chatbot[-1][0], f"[Local Message] 实验性函数调用出错: \n\n {tb_str} \n\n 当前代理可用性: \n\n {check_proxy(proxies)}")
|
88 |
yield chatbot, history, f'异常 {e}'
|
|
|
217 |
# files.extend(report_files)
|
218 |
chatbot.append(['汇总报告如何远程获取?', '汇总报告已经添加到右侧文件上传区,请查收。'])
|
219 |
return report_files, chatbot
|
220 |
+
|
221 |
+
def get_conf(*args):
|
222 |
+
# 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到
|
223 |
+
res = []
|
224 |
+
for arg in args:
|
225 |
+
try: r = getattr(importlib.import_module('config_private'), arg)
|
226 |
+
except: r = getattr(importlib.import_module('config'), arg)
|
227 |
+
res.append(r)
|
228 |
+
# 在读取API_KEY时,检查一下是不是忘了改config
|
229 |
+
if arg=='API_KEY' and len(r) != 51:
|
230 |
+
assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \
|
231 |
+
"(如果您刚更新过代码,请确保旧版config_private文件中没有遗留任何新增键值)"
|
232 |
+
return res
|