Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
d222bb9
1
Parent(s):
7dfecf7
解决未登录时可能的隐私问题
Browse files- ChuanhuChatbot.py +1 -2
- modules/models/base_model.py +3 -3
- modules/utils.py +6 -4
ChuanhuChatbot.py
CHANGED
|
@@ -143,8 +143,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 143 |
historyFileSelectDropdown = gr.Dropdown(
|
| 144 |
label=i18n("从列表中加载对话"),
|
| 145 |
choices=get_history_names(plain=True),
|
| 146 |
-
multiselect=False
|
| 147 |
-
value=get_history_names(plain=True)[0],
|
| 148 |
)
|
| 149 |
with gr.Column(scale=1):
|
| 150 |
historyRefreshBtn = gr.Button(i18n("🔄 刷新"))
|
|
|
|
| 143 |
historyFileSelectDropdown = gr.Dropdown(
|
| 144 |
label=i18n("从列表中加载对话"),
|
| 145 |
choices=get_history_names(plain=True),
|
| 146 |
+
multiselect=False
|
|
|
|
| 147 |
)
|
| 148 |
with gr.Column(scale=1):
|
| 149 |
historyRefreshBtn = gr.Button(i18n("🔄 刷新"))
|
modules/models/base_model.py
CHANGED
|
@@ -539,7 +539,7 @@ class BaseLLMModel:
|
|
| 539 |
def load_chat_history(self, filename, user_name):
|
| 540 |
logging.debug(f"{user_name} 加载对话历史中……")
|
| 541 |
logging.info(f"filename: {filename}")
|
| 542 |
-
if type(filename) != str:
|
| 543 |
filename = filename.name
|
| 544 |
try:
|
| 545 |
if "/" not in filename:
|
|
@@ -566,8 +566,8 @@ class BaseLLMModel:
|
|
| 566 |
return os.path.basename(filename), json_s["system"], json_s["chatbot"]
|
| 567 |
except:
|
| 568 |
# 没有对话历史或者对话历史解析失败
|
| 569 |
-
logging.info(f"没有找到对话历史记录 {
|
| 570 |
-
return
|
| 571 |
|
| 572 |
def auto_load(self):
|
| 573 |
if self.user_identifier == "":
|
|
|
|
| 539 |
def load_chat_history(self, filename, user_name):
|
| 540 |
logging.debug(f"{user_name} 加载对话历史中……")
|
| 541 |
logging.info(f"filename: {filename}")
|
| 542 |
+
if type(filename) != str and filename is not None:
|
| 543 |
filename = filename.name
|
| 544 |
try:
|
| 545 |
if "/" not in filename:
|
|
|
|
| 566 |
return os.path.basename(filename), json_s["system"], json_s["chatbot"]
|
| 567 |
except:
|
| 568 |
# 没有对话历史或者对话历史解析失败
|
| 569 |
+
logging.info(f"没有找到对话历史记录 {filename}")
|
| 570 |
+
return gr.update(), self.system_prompt, gr.update()
|
| 571 |
|
| 572 |
def auto_load(self):
|
| 573 |
if self.user_identifier == "":
|
modules/utils.py
CHANGED
|
@@ -77,9 +77,8 @@ def export_markdown(current_model, *args):
|
|
| 77 |
def load_chat_history(current_model, *args):
|
| 78 |
return current_model.load_chat_history(*args)
|
| 79 |
|
| 80 |
-
def upload_chat_history(current_model,
|
| 81 |
-
|
| 82 |
-
return current_model.load_chat_history(filename, username)
|
| 83 |
|
| 84 |
def set_token_upper_limit(current_model, *args):
|
| 85 |
return current_model.set_token_upper_limit(*args)
|
|
@@ -287,7 +286,10 @@ def get_file_names(dir, plain=False, filetypes=[".json"]):
|
|
| 287 |
|
| 288 |
def get_history_names(plain=False, user_name=""):
|
| 289 |
logging.debug(f"从用户 {user_name} 中获取历史记录文件名列表")
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
|
| 293 |
def load_template(filename, mode=0):
|
|
|
|
| 77 |
def load_chat_history(current_model, *args):
|
| 78 |
return current_model.load_chat_history(*args)
|
| 79 |
|
| 80 |
+
def upload_chat_history(current_model, *args):
|
| 81 |
+
return current_model.load_chat_history(*args)
|
|
|
|
| 82 |
|
| 83 |
def set_token_upper_limit(current_model, *args):
|
| 84 |
return current_model.set_token_upper_limit(*args)
|
|
|
|
| 286 |
|
| 287 |
def get_history_names(plain=False, user_name=""):
|
| 288 |
logging.debug(f"从用户 {user_name} 中获取历史记录文件名列表")
|
| 289 |
+
if user_name == "":
|
| 290 |
+
return ""
|
| 291 |
+
else:
|
| 292 |
+
return get_file_names(os.path.join(HISTORY_DIR, user_name), plain)
|
| 293 |
|
| 294 |
|
| 295 |
def load_template(filename, mode=0):
|