复用prompt, 可以选择继承所有上下文
This commit is contained in:
@ -113,7 +113,7 @@ class ChatBot(ChatBotFrame):
|
|||||||
"\t 重新生成:尝试在prompt不变的情况下多次生成结果,优中选优\n"
|
"\t 重新生成:尝试在prompt不变的情况下多次生成结果,优中选优\n"
|
||||||
self.pro_edit_txt = gr.Textbox(show_label=False, info='Prompt编辑区', lines=14,
|
self.pro_edit_txt = gr.Textbox(show_label=False, info='Prompt编辑区', lines=14,
|
||||||
placeholder=Tips).style(container=False)
|
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)
|
container=False)
|
||||||
with gr.Row(elem_id='sm_btn'):
|
with gr.Row(elem_id='sm_btn'):
|
||||||
self.pro_reuse_btn = gr.Button("复用Prompt", variant="secondary").style(size='sm').style(full_width=False)
|
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_func_prompt, self.pro_fp_state])
|
||||||
self.pro_reuse_btn.click(
|
self.pro_reuse_btn.click(
|
||||||
fn=func_box.reuse_chat,
|
fn=func_box.reuse_chat,
|
||||||
inputs=[self.pro_results, self.chatbot, self.history],
|
inputs=[self.pro_results, self.chatbot, self.history, self.pro_name_txt],
|
||||||
outputs=[self.chatbot, self.history, self.txt, self.tabs_chatbot]
|
outputs=[self.chatbot, self.history, self.txt, self.tabs_chatbot, self.pro_name_txt]
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_function_chat(self):
|
def draw_function_chat(self):
|
||||||
|
|||||||
12
func_box.py
12
func_box.py
@ -517,16 +517,20 @@ base_path = os.path.dirname(__file__)
|
|||||||
prompt_path = os.path.join(base_path, 'prompt_users')
|
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'^<div class="markdown-body"><p>|<\/p><\/div>$')
|
||||||
if result is None or result == []:
|
if result is None or result == []:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
if pro_numb:
|
||||||
|
chatbot.append(result)
|
||||||
|
history += [pattern.sub('', i) for i in result]
|
||||||
else:
|
else:
|
||||||
chatbot.append(result[-1])
|
chatbot.append(result[-1])
|
||||||
history += result[-1]
|
history += [pattern.sub('', i) for i in result[-2:]]
|
||||||
pattern = re.compile(r'^<div class="markdown-body"><p>|<\/p><\/div>$')
|
|
||||||
i_say = pattern.sub('', chatbot[-1][0])
|
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:
|
class YamlHandle:
|
||||||
|
|||||||
Reference in New Issue
Block a user