diff --git a/__main__.py b/__main__.py index e272c58..63ec238 100644 --- a/__main__.py +++ b/__main__.py @@ -7,9 +7,9 @@ from toolbox import format_io, find_free_port, on_file_uploaded, on_report_gener DummyWith # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 -proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY = \ +proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, API_KEY, AVAIL_LLM_MODELS = \ get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', - 'API_KEY') + 'API_KEY', 'AVAIL_LLM_MODELS') # 如果WEB_PORT是-1, 则随机选取WEB端口 PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT @@ -125,10 +125,15 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= label="Top-p (nucleus sampling)", ) temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature", ) + max_length_sl = gr.Slider(minimum=256, maximum=4096, value=512, step=1, interactive=True, + label="Local LLM MaxLength", ) + models_box = gr.CheckboxGroup(["input加密", "prompt提示"], value=["input加密", "prompt提示"], label="对话模式") checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区") + md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style( + container=False) gr.Markdown(description) @@ -148,7 +153,7 @@ with gr.Blocks(title="ChatGPT 学术优化", theme=set_theme, analytics_enabled= [area_basic_fn, area_crazy_fn, area_input_primary, txt]) # 整理反复出现的控件句柄组合 # submitBtn.info - input_combo = [cookies, txt, top_p, temperature, chatbot, history, system_prompt, models_box] + input_combo = [cookies, max_length_sl, md_dropdown, txt, top_p, temperature, chatbot, history, system_prompt, models_box] output_combo = [cookies, chatbot, history, status] predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo) # 提交按钮、重置按钮 diff --git a/toolbox.py b/toolbox.py index 3066c6f..e52546c 100644 --- a/toolbox.py +++ b/toolbox.py @@ -27,7 +27,7 @@ def ArgsGeneralWrapper(f): """ 装饰器函数,用于重组输入参数,改变输入参数的顺序与结构。 """ - def decorated(cookies, max_length, llm_model, txt, txt2, top_p, temperature, chatbot, history, system_prompt, *args): + def decorated(cookies, max_length, llm_model, txt, top_p, temperature, chatbot, history, system_prompt, models, ipaddr:gr.Request, *args): txt_passon = txt if 'input加密' in models: txt_passon = func_box.encryption_str(txt) # 引入一个有cookie的chatbot @@ -40,14 +40,14 @@ def ArgsGeneralWrapper(f): 'llm_model': llm_model, 'top_p':top_p, 'max_length': max_length, - 'temperature':temperature, + 'temperature': temperature, + 'ipaddr': ipaddr.client.host } plugin_kwargs = { # 目前还没有 } chatbot_with_cookie = ChatBotWithCookies(cookies) chatbot_with_cookie.write_list(chatbot) - # logging.info(f'[user_click]_{adder.client.host} {txt_passon} ----') yield from f(txt_passon, llm_kwargs, plugin_kwargs, chatbot_with_cookie, history, system_prompt, *args) return decorated