解决下拉插件的问题哦
This commit is contained in:
19
__main__.py
19
__main__.py
@ -1,6 +1,6 @@
|
||||
import os
|
||||
import gradio as gr
|
||||
from request_llm.bridge_chatgpt import predict
|
||||
from request_llm.bridge_all import predict
|
||||
from toolbox import format_io, find_free_port, on_file_uploaded, on_report_generated, get_user_upload, \
|
||||
get_user_download, get_conf, ArgsGeneralWrapper, DummyWith
|
||||
|
||||
@ -55,7 +55,7 @@ class ChatBotFrame:
|
||||
|
||||
def __init__(self):
|
||||
self.cancel_handles = []
|
||||
self.initial_prompt = "Serve me as a writing and programming assistant."
|
||||
self.initial_prompt = "In answer to my question, Think about what are some alternative perspectives"
|
||||
self.title_html = f"<h1 align=\"center\">ChatGPT For Tester {get_current_version()}</h1>"
|
||||
self.description = """代码开源和更新[地址🚀](https://github.com/binary-husky/chatgpt_academic),感谢热情的[开发者们❤️](https://github.com/binary-husky/chatgpt_academic/graphs/contributors)"""
|
||||
|
||||
@ -73,7 +73,7 @@ class ChatBot(ChatBotFrame):
|
||||
|
||||
def draw_chatbot(self):
|
||||
with gr.Box():
|
||||
self.chatbot = gr.Chatbot()
|
||||
self.chatbot = gr.Chatbot(label=f"当前模型:{LLM_MODEL}")
|
||||
self.chatbot.style(height=CHATBOT_HEIGHT)
|
||||
self.history = gr.State([])
|
||||
with gr.Row():
|
||||
@ -117,7 +117,7 @@ class ChatBot(ChatBotFrame):
|
||||
self.variant = crazy_fns[k]["Color"] if "Color" in crazy_fns[k] else "secondary"
|
||||
crazy_fns[k]["Button"] = gr.Button(k, variant=self.variant)
|
||||
crazy_fns[k]["Button"].style(size="sm")
|
||||
with gr.Accordion("更多函数插件", open=True):
|
||||
with gr.Accordion("更多函数插件", open=False):
|
||||
dropdown_fn_list = [k for k in crazy_fns.keys() if
|
||||
not crazy_fns[k].get("AsButton", True)]
|
||||
self.dropdown = gr.Dropdown(dropdown_fn_list, value=r"打开插件列表", label="").style(
|
||||
@ -126,13 +126,14 @@ class ChatBot(ChatBotFrame):
|
||||
|
||||
def draw_setting_chat(self):
|
||||
with gr.Tab('Setting'):
|
||||
with gr.Accordion("展开SysPrompt & 交互界面布局 & Github地址", open=True):
|
||||
self.system_prompt = gr.Textbox(show_label=True, lines=2, placeholder=f"System Prompt", label="System prompt", value=self.initial_prompt)
|
||||
self.top_p = gr.Slider(minimum=-0, maximum=1.0, value=1.0, step=0.01, interactive=True, label="Top-p (nucleus sampling)", )
|
||||
self.temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature", )
|
||||
self.max_length_sl = gr.Slider(minimum=256, maximum=4096, value=512, step=1, interactive=True, label="MaxLength", )
|
||||
self.models_box = gr.CheckboxGroup(["input加密"], value=["input加密"], label="对话模式")
|
||||
self.system_prompt = gr.Textbox(show_label=True, lines=2, placeholder=f"System Prompt", label="System prompt", value=self.initial_prompt)
|
||||
self.md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
|
||||
|
||||
|
||||
# temp = gr.Markdown(self.description)
|
||||
|
||||
def draw_goals_auto(self):
|
||||
@ -203,11 +204,14 @@ class ChatBot(ChatBotFrame):
|
||||
def route(k, *args, **kwargs):
|
||||
if k in [r"打开插件列表", r"请先从插件列表中选择"]: return
|
||||
yield from ArgsGeneralWrapper(crazy_fns[k]["Function"])(*args , **kwargs)
|
||||
self.click_handle = self.switchy_bt.click(route, [self.switchy_bt, *self.input_combo, gr.State(PORT)], self.output_combo)
|
||||
self.click_handle = self.switchy_bt.click(route, [self.switchy_bt, *self.input_combo], self.output_combo)
|
||||
self.click_handle.then(on_report_generated, [self.file_upload, self.chatbot], [self.file_upload, self.chatbot])
|
||||
self.cancel_handles.append(self.click_handle)
|
||||
# 终止按钮的回调函数注册
|
||||
self.stopBtn.click(fn=None, inputs=None, outputs=None, cancels=self.cancel_handles)
|
||||
def on_md_dropdown_changed(k):
|
||||
return {self.chatbot: gr.update(label="当前模型:"+k)}
|
||||
self.md_dropdown.select(on_md_dropdown_changed, [self.md_dropdown], [self.chatbot])
|
||||
|
||||
|
||||
def signals_auto_input(self):
|
||||
@ -231,7 +235,6 @@ class ChatBot(ChatBotFrame):
|
||||
def open():
|
||||
time.sleep(2) # 打开浏览器
|
||||
webbrowser.open_new_tab(f"http://localhost:{PORT}/?__dark-theme=true")
|
||||
|
||||
threading.Thread(target=open, name="open-browser", daemon=True).start()
|
||||
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
||||
# threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start()
|
||||
|
||||
@ -3,6 +3,6 @@ ai_goals:
|
||||
- ''
|
||||
- ''
|
||||
- ''
|
||||
ai_name: Entrepreneur-GPT
|
||||
ai_role: CCzcccCZCC
|
||||
ai_name: 小爱
|
||||
ai_role: 我希望世界和平
|
||||
api_budget: 0.0
|
||||
|
||||
@ -212,8 +212,8 @@ def agent_main(name, role, goals, budget,
|
||||
_start = obj['start'].update(visible=False)
|
||||
_next = obj['next'].update(visible=True)
|
||||
_text = obj['text'].update(visible=True, interactive=True)
|
||||
chat, his = func_box.chat_history(logger.output_content)
|
||||
yield from update_stream_ui(user='Auto-GPT Start!', gpt=chat, _start=_start, _next=_next, _text=_text)
|
||||
# chat, his = func_box.chat_history(logger.output_content)
|
||||
# yield from update_stream_ui(user='Auto-GPT Start!', gpt=chat, _start=_start, _next=_next, _text=_text)
|
||||
agent.start_interaction_loop()
|
||||
chat, his = func_box.chat_history(logger.output_content)
|
||||
yield from update_stream_ui(user='Auto-GPT Start!', gpt=chat, _start=_start, _next=_next, _text=_text)
|
||||
|
||||
@ -61,7 +61,7 @@ def get_core_functions():
|
||||
},
|
||||
"找图片": {
|
||||
"Prefix": r"我需要你找一张网络图片。使用Unsplash API(https://source.unsplash.com/960x640/?<英语关键词>)获取图片URL," +
|
||||
r"然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:" + "\n\n",
|
||||
r"然后请使用Markdown格式封装,并且不要有反斜线,不要用代码块。现在,请按以下描述给我发送图片:" + "\n",
|
||||
"Suffix": r"",
|
||||
},
|
||||
"解释代码": {
|
||||
|
||||
@ -29,10 +29,11 @@ def get_crazy_functions():
|
||||
},
|
||||
"解析整个Python项目": {
|
||||
"Color": "stop", # 按钮颜色
|
||||
"AsButton": False,
|
||||
"Function": HotReload(解析一个Python项目)
|
||||
},
|
||||
"保存当前的对话": {
|
||||
"AsButton":False,
|
||||
"AsButton": True,
|
||||
"Function": HotReload(对话历史存档)
|
||||
},
|
||||
"[测试功能] 解析Jupyter Notebook文件": {
|
||||
@ -204,7 +205,7 @@ def get_crazy_functions():
|
||||
function_plugins.update({
|
||||
"连接网络回答问题(先输入问题,再点击按钮,需要访问谷歌)": {
|
||||
"Color": "stop",
|
||||
"AsButton": False, # 加入下拉菜单中
|
||||
"AsButton": True, # 加入下拉菜单中
|
||||
"Function": HotReload(连接网络回答问题)
|
||||
}
|
||||
})
|
||||
|
||||
@ -111,3 +111,4 @@ def 理解PDF文档内容标准文件输入(txt, llm_kwargs, plugin_kwargs, chat
|
||||
txt = file_manifest[0]
|
||||
# 开始正式执行任务
|
||||
yield from 解析PDF(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt)
|
||||
|
||||
|
||||
6
main.py
6
main.py
@ -128,9 +128,9 @@ def main():
|
||||
ret.update({plugin_advanced_arg: gr.update(visible=("插件参数区" in a))})
|
||||
if "底部输入区" in a: ret.update({txt: gr.update(value="")})
|
||||
return ret
|
||||
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, txt2, clearBtn, clearBtn2, plugin_advanced_arg] )
|
||||
checkboxes.select(fn_area_visibility, [checkboxes], [area_basic_fn, area_crazy_fn, area_input_primary, area_input_secondary, txt, clearBtn, clearBtn2, plugin_advanced_arg] )
|
||||
# 整理反复出现的控件句柄组合
|
||||
input_combo = [cookies, max_length_sl, md_dropdown, txt, txt2, top_p, temperature, chatbot, history, system_prompt, plugin_advanced_arg]
|
||||
input_combo = [cookies, max_length_sl, md_dropdown, txt, top_p, temperature, chatbot, history, system_prompt, plugin_advanced_arg]
|
||||
output_combo = [cookies, chatbot, history, status]
|
||||
predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=input_combo, outputs=output_combo)
|
||||
# 提交按钮、重置按钮
|
||||
@ -147,7 +147,7 @@ def main():
|
||||
click_handle = functional[k]["Button"].click(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True), gr.State(k)], outputs=output_combo)
|
||||
cancel_handles.append(click_handle)
|
||||
# 文件上传区,接收文件后与chatbot的互动
|
||||
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt, txt2, checkboxes], [chatbot, txt, txt2])
|
||||
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt ], [chatbot, txt])
|
||||
# 函数插件-固定按钮区
|
||||
for k in crazy_fns:
|
||||
if not crazy_fns[k].get("AsButton", True): continue
|
||||
|
||||
Reference in New Issue
Block a user