Spaces:
Sleeping
Sleeping
fix. 重命名自动添加序号
Browse files- modules/models/base_model.py +0 -2
- modules/models/models.py +3 -0
- modules/utils.py +9 -0
modules/models/base_model.py
CHANGED
|
@@ -679,8 +679,6 @@ class BaseLLMModel:
|
|
| 679 |
else:
|
| 680 |
return gr.update()
|
| 681 |
|
| 682 |
-
|
| 683 |
-
|
| 684 |
def auto_save(self, chatbot):
|
| 685 |
save_file(self.history_file_path, self.system_prompt,
|
| 686 |
self.history, chatbot, self.user_identifier)
|
|
|
|
| 679 |
else:
|
| 680 |
return gr.update()
|
| 681 |
|
|
|
|
|
|
|
| 682 |
def auto_save(self, chatbot):
|
| 683 |
save_file(self.history_file_path, self.system_prompt,
|
| 684 |
self.history, chatbot, self.user_identifier)
|
modules/models/models.py
CHANGED
|
@@ -228,6 +228,9 @@ class OpenAIClient(BaseLLMModel):
|
|
| 228 |
ret = super().set_key(new_access_key)
|
| 229 |
self._refresh_header()
|
| 230 |
return ret
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
|
| 233 |
class ChatGLM_Client(BaseLLMModel):
|
|
|
|
| 228 |
ret = super().set_key(new_access_key)
|
| 229 |
self._refresh_header()
|
| 230 |
return ret
|
| 231 |
+
|
| 232 |
+
# def auto_name_chat_history(self, user_question, chatbot, user_name):
|
| 233 |
+
# return super().auto_name_chat_history(user_question, chatbot, user_name)
|
| 234 |
|
| 235 |
|
| 236 |
class ChatGLM_Client(BaseLLMModel):
|
modules/utils.py
CHANGED
|
@@ -341,10 +341,19 @@ def save_file(filename, system, history, chatbot, user_name):
|
|
| 341 |
filename += ".json"
|
| 342 |
|
| 343 |
json_s = {"system": system, "history": history, "chatbot": chatbot}
|
|
|
|
| 344 |
if "/" in filename or "\\" in filename:
|
| 345 |
history_file_path = filename
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
else:
|
| 347 |
history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
with open(history_file_path, "w", encoding='utf-8') as f:
|
| 349 |
json.dump(json_s, f, ensure_ascii=False)
|
| 350 |
|
|
|
|
| 341 |
filename += ".json"
|
| 342 |
|
| 343 |
json_s = {"system": system, "history": history, "chatbot": chatbot}
|
| 344 |
+
repeat_file_index = 2
|
| 345 |
if "/" in filename or "\\" in filename:
|
| 346 |
history_file_path = filename
|
| 347 |
+
dir_path, file_name = os.path.split(history_file_path)
|
| 348 |
+
while os.path.exists(history_file_path):
|
| 349 |
+
history_file_path = os.path.join(dir_path, f"{repeat_file_index}_{file_name}")
|
| 350 |
+
repeat_file_index += 1
|
| 351 |
else:
|
| 352 |
history_file_path = os.path.join(HISTORY_DIR, user_name, filename)
|
| 353 |
+
while os.path.exists(history_file_path):
|
| 354 |
+
history_file_path = os.path.join(HISTORY_DIR, user_name, f"{repeat_file_index}_{filename}")
|
| 355 |
+
repeat_file_index += 1
|
| 356 |
+
|
| 357 |
with open(history_file_path, "w", encoding='utf-8') as f:
|
| 358 |
json.dump(json_s, f, ensure_ascii=False)
|
| 359 |
|