Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
•
43981f0
1
Parent(s):
d2d74c3
feat: 加入了删除对话历史记录的功能 #756
Browse files- ChuanhuChatbot.py +6 -2
- modules/models/base_model.py +16 -0
- modules/utils.py +3 -0
ChuanhuChatbot.py
CHANGED
@@ -141,8 +141,11 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
141 |
choices=get_history_names(plain=True),
|
142 |
multiselect=False
|
143 |
)
|
144 |
-
with gr.
|
145 |
-
|
|
|
|
|
|
|
146 |
with gr.Row():
|
147 |
with gr.Column(scale=6):
|
148 |
saveFileName = gr.Textbox(
|
@@ -426,6 +429,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
426 |
show_progress=True,
|
427 |
)
|
428 |
historyRefreshBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
|
|
|
429 |
historyFileSelectDropdown.change(**load_history_from_file_args)
|
430 |
downloadFile.change(upload_chat_history, [current_model, downloadFile, user_name], [saveFileName, systemPromptTxt, chatbot])
|
431 |
|
|
|
141 |
choices=get_history_names(plain=True),
|
142 |
multiselect=False
|
143 |
)
|
144 |
+
with gr.Row():
|
145 |
+
with gr.Column(min_width=42, scale=1):
|
146 |
+
historyRefreshBtn = gr.Button(i18n("🔄 刷新"))
|
147 |
+
with gr.Column(min_width=42, scale=1):
|
148 |
+
historyDeleteBtn = gr.Button(i18n("🗑️ 删除"))
|
149 |
with gr.Row():
|
150 |
with gr.Column(scale=6):
|
151 |
saveFileName = gr.Textbox(
|
|
|
429 |
show_progress=True,
|
430 |
)
|
431 |
historyRefreshBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
|
432 |
+
historyDeleteBtn.click(delete_chat_history, [current_model, historyFileSelectDropdown, user_name], [status_display, historyFileSelectDropdown])
|
433 |
historyFileSelectDropdown.change(**load_history_from_file_args)
|
434 |
downloadFile.change(upload_chat_history, [current_model, downloadFile, user_name], [saveFileName, systemPromptTxt, chatbot])
|
435 |
|
modules/models/base_model.py
CHANGED
@@ -665,6 +665,22 @@ class BaseLLMModel:
|
|
665 |
logging.info(f"没有找到对话历史记录 {filename}")
|
666 |
return gr.update(), self.system_prompt, gr.update()
|
667 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
668 |
def auto_load(self):
|
669 |
if self.user_identifier == "":
|
670 |
self.reset()
|
|
|
665 |
logging.info(f"没有找到对话历史记录 {filename}")
|
666 |
return gr.update(), self.system_prompt, gr.update()
|
667 |
|
668 |
+
def delete_chat_history(self, filename, user_name):
|
669 |
+
if filename == "":
|
670 |
+
return i18n("你没有选择任何对话历史"), gr.update()
|
671 |
+
if not filename.endswith(".json"):
|
672 |
+
filename += ".json"
|
673 |
+
if "/" not in filename:
|
674 |
+
history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
|
675 |
+
else:
|
676 |
+
history_file_path = filename
|
677 |
+
try:
|
678 |
+
os.remove(history_file_path)
|
679 |
+
return i18n("删除对话历史成功"), get_history_names(False, user_name)
|
680 |
+
except:
|
681 |
+
logging.info(f"删除对话历史失败 {history_file_path}")
|
682 |
+
return i18n("对话历史")+filename+i18n("已经被删除啦"), gr.update()
|
683 |
+
|
684 |
def auto_load(self):
|
685 |
if self.user_identifier == "":
|
686 |
self.reset()
|
modules/utils.py
CHANGED
@@ -47,6 +47,9 @@ def set_key(current_model, *args):
|
|
47 |
def load_chat_history(current_model, *args):
|
48 |
return current_model.load_chat_history(*args)
|
49 |
|
|
|
|
|
|
|
50 |
def interrupt(current_model, *args):
|
51 |
return current_model.interrupt(*args)
|
52 |
|
|
|
47 |
def load_chat_history(current_model, *args):
|
48 |
return current_model.load_chat_history(*args)
|
49 |
|
50 |
+
def delete_chat_history(current_model, *args):
|
51 |
+
return current_model.delete_chat_history(*args)
|
52 |
+
|
53 |
def interrupt(current_model, *args):
|
54 |
return current_model.interrupt(*args)
|
55 |
|