From e3e4fa19a22742839a5cca525bf422a458f32838 Mon Sep 17 00:00:00 2001 From: fulyaec Date: Fri, 31 Mar 2023 16:24:40 +0800 Subject: [PATCH] refactor and enhance --- main.py | 5 ++--- toolbox.py | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index c69795a..3033e39 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION = \ # 如果WEB_PORT是-1, 则随机选取WEB端口 PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT -AUTHENTICATION = None if AUTHENTICATION == [] else AUTHENTICATION +if not AUTHENTICATION: AUTHENTICATION = None initial_prompt = "Serve me as a writing and programming assistant." title_html = """

ChatGPT 学术优化

""" @@ -105,8 +105,7 @@ def auto_opentab_delay(): def open(): time.sleep(2) webbrowser.open_new_tab(f'http://localhost:{PORT}') - t = threading.Thread(target=open) - t.daemon = True; t.start() + threading.Thread(target=open, name="open-browser", daemon=True).start() auto_opentab_delay() demo.title = "ChatGPT 学术优化" diff --git a/toolbox.py b/toolbox.py index d96b3f6..326740a 100644 --- a/toolbox.py +++ b/toolbox.py @@ -226,13 +226,10 @@ def get_conf(*args): except: r = getattr(importlib.import_module('config'), arg) res.append(r) # 在读取API_KEY时,检查一下是不是忘了改config - if arg=='API_KEY' and len(r) != 51: - assert False, "正确的API_KEY密钥是51位,请在config文件中修改API密钥, 添加海外代理之后再运行。" + \ + assert arg != 'API_KEY' or len(r) == 51, "正确的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 \ No newline at end of file + import re + return re.sub(r"\s+", " ", txt) \ No newline at end of file