diff --git a/__main__.py b/__main__.py index 65da218..9b69bdf 100644 --- a/__main__.py +++ b/__main__.py @@ -224,6 +224,31 @@ class ChatBot(ChatBotFrame): container=False) # temp = gr.Markdown(self.description) + def draw_goals_auto(self): + with gr.Row(): + self.ai_name = gr.Textbox(show_label=False, placeholder="给Ai一个名字").style(container=False) + with gr.Row(): + self.ai_role = gr.Textbox(lines=5, show_label=False, placeholder="请输入你的需求").style( + container=False) + with gr.Row(): + self.ai_goal_list = gr.Dataframe(headers=['Goals'], interactive=True, row_count=4, + col_count=(1, 'fixed'), type='array') + with gr.Row(): + self.ai_budget = gr.Number(show_label=False, value=0.0, + info="关于本次项目的预算,超过预算自动停止,默认无限").style(container=False) + + + def draw_next_auto(self): + with gr.Row(): + self.text_continue = gr.Textbox(visible=False, show_label=False, + placeholder="请根据提示输入执行命令").style(container=False) + with gr.Row(): + self.submit_start = gr.Button("Start", variant='primary') + self.submit_next = gr.Button("Next", visible=False, variant='primary') + self.submit_stop = gr.Button("Stop", variant="stop") + self.agent_obj = gr.State({'obj': None, "start": self.submit_start, + "next": self.submit_next, "text": self.text_continue}) + def signals_input_setting(self): # 注册input @@ -296,6 +321,15 @@ class ChatBot(ChatBotFrame): self.md_dropdown.select(on_md_dropdown_changed, [self.md_dropdown], [self.chatbot]) + def signals_auto_input(self): + from autogpt.cli import agent_main + self.auto_input_combo = [self.ai_name, self.ai_role, self.ai_goal_list, self.ai_budget, + self.cookies, self.chatbot, self.history, + self.agent_obj] + self.auto_output_combo = [self.cookies, self.chatbot, self.history, self.status, + self.agent_obj, self.submit_start, self.submit_next, self.text_continue] + self.submit_start.click(fn=agent_main, inputs=self.auto_input_combo, outputs=self.auto_output_combo) + # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数 def auto_opentab_delay(self, is_open=False): import threading, webbrowser, time @@ -327,14 +361,18 @@ class ChatBot(ChatBotFrame): self.draw_function_chat() self.draw_public_chat() self.draw_setting_chat() + + # 绘制autogpt模组 + with gr.TabItem('Auto-GPT'): + self.draw_next_auto() + self.draw_goals_auto() # 绘制列2 with gr.Column(scale=100): - with gr.Tabs() as self.tabs_chat: - with gr.TabItem('Chatbot') as self.chat_tab: - # self.draw_chatbot() - pass - with gr.TabItem('Prompt检索/编辑') as self.prompt_tab: - self.draw_prompt() + with gr.Tab('Chatbot') as self.chat_tab: + # self.draw_chatbot() + pass + with gr.Tab('Prompt检索/编辑') as self.prompt_tab: + self.draw_prompt() with self.chat_tab: # 使用 gr.State()对组件进行拷贝时,如果之前绘制了Markdown格式,会导致启动崩溃,所以将 markdown相关绘制放在最后 @@ -347,6 +385,7 @@ class ChatBot(ChatBotFrame): self.signals_prompt_func() self.signals_public() self.signals_prompt_edit() + # self.signals_auto_input() # Start self.auto_opentab_delay() diff --git a/func_box.py b/func_box.py index f54ca1a..b146647 100644 --- a/func_box.py +++ b/func_box.py @@ -475,6 +475,7 @@ def show_prompt_result(index, data: gr.Dataset, chatbot): return chatbot + def thread_write_chat(chatbot): """ 对话记录写入数据库 @@ -494,6 +495,18 @@ base_path = os.path.dirname(__file__) prompt_path = os.path.join(base_path, 'prompt_users') +def reuse_chat(result, chatbot, history): + """复用对话记录""" + if result is None or result == []: + pass + else: + chatbot.append(result[-1]) + history += result[-1] + pattern = re.compile(r'^
|<\/p><\/div>$') + i_say = pattern.sub('', chatbot[-1][0]) + return chatbot, history, i_say, gr.Tabs.update(selected='chatbot') + + class YamlHandle: def __init__(self, file=os.path.join(prompt_path, 'ai_common.yaml')): diff --git a/theme.py b/theme.py index e912cff..c123f9c 100644 --- a/theme.py +++ b/theme.py @@ -123,6 +123,12 @@ advanced_css = """ width: 100%; margin-bottom: 35px !important; } +#sm_btn { + display: flex; + flex-wrap: unset !important; + gap: 5px !important; + width: var(--size-full); +} textarea { resize: none; height: 100%; /* 填充父元素的高度 */