From 43d59d936f9880a778d9dce07748ea5f7cb0228d Mon Sep 17 00:00:00 2001 From: Tuchuanhuhuhu Date: Tue, 28 Mar 2023 23:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B9=B6=E8=A1=8C=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=B8=8E=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 12 +++++++++--- main.py | 15 ++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index aa85bc0..bff413b 100644 --- a/config.py +++ b/config.py @@ -6,7 +6,7 @@ API_URL = "https://api.openai.com/v1/chat/completions" USE_PROXY = False if USE_PROXY: # 代理网络的地址,打开你的科学上网软件查看代理的协议(socks5/http)、地址(localhost)和端口(11284) - proxies = { "http": "socks5h://localhost:11284", "https": "socks5h://localhost:11284", } + proxies = { "http": "socks5h://localhost:11284", "https": "socks5h://localhost:11284", } print('网络代理状态:运行。') else: proxies = None @@ -25,5 +25,11 @@ MAX_RETRY = 2 LLM_MODEL = "gpt-3.5-turbo" # 检查一下是不是忘了改config -if API_KEY == "sk-此处填API秘钥": - assert False, "请在config文件中修改API密钥, 添加海外代理之后再运行" \ No newline at end of file +if len(API_KEY) != 51: + assert False, "请在config文件中修改API密钥, 添加海外代理之后再运行" + +# 设置并行使用的线程数 +CONCURRENT_COUNT = 100 + +# 设置用户名和密码 +AUTHENTICATION = [] # [("username", "password"), ("username2", "password2"), ...] \ No newline at end of file diff --git a/main.py b/main.py index eecd126..61de4b7 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,15 @@ import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染 -import gradio as gr +import gradio as gr from predict import predict from toolbox import format_io, find_free_port # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 -try: from config_private import proxies, WEB_PORT, LLM_MODEL -except: from config import proxies, WEB_PORT, LLM_MODEL +try: from config_private import proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION +except: from config import 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 initial_prompt = "Serve me as a writing and programming assistant." title_html = """

ChatGPT 学术优化

""" @@ -16,7 +17,7 @@ title_html = """

ChatGPT 学术优化

""" # 问询记录, python 版本建议3.9+(越新越好) import logging os.makedirs('gpt_log', exist_ok=True) -try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8') +try:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO, encoding='utf-8') except:logging.basicConfig(filename='gpt_log/chat_secrets.log', level=logging.INFO) print('所有问询记录将自动保存在本地目录./gpt_log/chat_secrets.log, 请注意自我隐私保护哦!') @@ -78,11 +79,11 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo: txt.submit(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay]) submitBtn.click(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt], [chatbot, history, statusDisplay], show_progress=True) for k in functional: - functional[k]["Button"].click(predict, + functional[k]["Button"].click(predict, [txt, top_p, temperature, chatbot, history, systemPromptTxt, TRUE, gr.State(k)], [chatbot, history, statusDisplay], show_progress=True) file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt]) for k in crazy_functional: - click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"], + click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"], [txt, top_p, temperature, chatbot, history, systemPromptTxt, gr.State(PORT)], [chatbot, history, statusDisplay] ) try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot]) @@ -90,4 +91,4 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo: demo.title = "ChatGPT 学术优化" -demo.queue().launch(server_name="0.0.0.0", share=True, server_port=PORT, inbrowser=True) +demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", share=True, server_port=PORT, inbrowser=True, auth=AUTHENTICATION)