Spaces:
Sleeping
Sleeping
fix. 修复重复保存的bug
Browse files- modules/models/base_model.py +8 -0
- modules/utils.py +0 -7
modules/models/base_model.py
CHANGED
@@ -667,6 +667,14 @@ class BaseLLMModel:
|
|
667 |
if not filename.endswith(".json"):
|
668 |
filename += ".json"
|
669 |
self.delete_chat_history(self.history_file_path, user_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
self.history_file_path = filename
|
671 |
save_file(filename, self.system_prompt, self.history, chatbot, user_name)
|
672 |
return init_history_list(user_name)
|
|
|
667 |
if not filename.endswith(".json"):
|
668 |
filename += ".json"
|
669 |
self.delete_chat_history(self.history_file_path, user_name)
|
670 |
+
# 命名重复检测
|
671 |
+
repeat_file_index = 2
|
672 |
+
full_path = os.path.join(HISTORY_DIR, user_name, filename)
|
673 |
+
while os.path.exists(full_path):
|
674 |
+
full_path = os.path.join(HISTORY_DIR, user_name, f"{repeat_file_index}_{filename}")
|
675 |
+
repeat_file_index += 1
|
676 |
+
filename = os.path.basename(full_path)
|
677 |
+
|
678 |
self.history_file_path = filename
|
679 |
save_file(filename, self.system_prompt, self.history, chatbot, user_name)
|
680 |
return init_history_list(user_name)
|
modules/utils.py
CHANGED
@@ -346,15 +346,8 @@ def save_file(filename, system, history, chatbot, user_name):
|
|
346 |
repeat_file_index = 2
|
347 |
if "/" in filename or "\\" in filename:
|
348 |
history_file_path = filename
|
349 |
-
dir_path, file_name = os.path.split(history_file_path)
|
350 |
-
while os.path.exists(history_file_path):
|
351 |
-
history_file_path = os.path.join(dir_path, f"{repeat_file_index}_{file_name}")
|
352 |
-
repeat_file_index += 1
|
353 |
else:
|
354 |
history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
|
355 |
-
while os.path.exists(history_file_path):
|
356 |
-
history_file_path = os.path.join(HISTORY_DIR, user_name, f"{repeat_file_index}_{filename}")
|
357 |
-
repeat_file_index += 1
|
358 |
|
359 |
with open(history_file_path, "w", encoding='utf-8') as f:
|
360 |
json.dump(json_s, f, ensure_ascii=False)
|
|
|
346 |
repeat_file_index = 2
|
347 |
if "/" in filename or "\\" in filename:
|
348 |
history_file_path = filename
|
|
|
|
|
|
|
|
|
349 |
else:
|
350 |
history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
|
|
|
|
|
|
|
351 |
|
352 |
with open(history_file_path, "w", encoding='utf-8') as f:
|
353 |
json.dump(json_s, f, ensure_ascii=False)
|