diff --git a/__main__.py b/__main__.py index ea6a191..ad4917b 100644 --- a/__main__.py +++ b/__main__.py @@ -113,7 +113,7 @@ class ChatBot(ChatBotFrame): "\t 重新生成:尝试在prompt不变的情况下多次生成结果,优中选优\n" self.pro_edit_txt = gr.Textbox(show_label=False, info='Prompt编辑区', lines=14, placeholder=Tips).style(container=False) - self.pro_name_txt = gr.Textbox(show_label=False, placeholder='prompt功能名', ).style( + self.pro_name_txt = gr.Textbox(show_label=False, placeholder='是否全复用prompt/prompt功能名', ).style( container=False) with gr.Row(elem_id='sm_btn'): self.pro_reuse_btn = gr.Button("复用Prompt", variant="secondary").style(size='sm').style(full_width=False) @@ -141,8 +141,8 @@ class ChatBot(ChatBotFrame): self.pro_func_prompt, self.pro_fp_state]) self.pro_reuse_btn.click( fn=func_box.reuse_chat, - inputs=[self.pro_results, self.chatbot, self.history], - outputs=[self.chatbot, self.history, self.txt, self.tabs_chatbot] + inputs=[self.pro_results, self.chatbot, self.history, self.pro_name_txt], + outputs=[self.chatbot, self.history, self.txt, self.tabs_chatbot, self.pro_name_txt] ) def draw_function_chat(self): diff --git a/func_box.py b/func_box.py index 458cdda..f73b135 100644 --- a/func_box.py +++ b/func_box.py @@ -517,16 +517,20 @@ base_path = os.path.dirname(__file__) prompt_path = os.path.join(base_path, 'prompt_users') -def reuse_chat(result, chatbot, history): +def reuse_chat(result, chatbot, history, pro_numb): """复用对话记录""" + pattern = re.compile(r'^

|<\/p><\/div>$') if result is None or result == []: pass else: - chatbot.append(result[-1]) - history += result[-1] - pattern = re.compile(r'^

|<\/p><\/div>$') + if pro_numb: + chatbot.append(result) + history += [pattern.sub('', i) for i in result] + else: + chatbot.append(result[-1]) + history += [pattern.sub('', i) for i in result[-2:]] i_say = pattern.sub('', chatbot[-1][0]) - return chatbot, history, i_say, gr.Tabs.update(selected='chatbot') + return chatbot, history, i_say, gr.Tabs.update(selected='chatbot'), '' class YamlHandle: