diff --git a/ChuanhuChatbot.py b/ChuanhuChatbot.py index 269cb0f1..5028100f 100644 --- a/ChuanhuChatbot.py +++ b/ChuanhuChatbot.py @@ -575,7 +575,7 @@ def create_greeting(request: gr.Request): auto_name_chat_history_args = dict( fn=auto_name_chat_history, - inputs=[current_model, name_chat_method, user_question, chatbot, single_turn_checkbox], + inputs=[current_model, name_chat_method, user_question, single_turn_checkbox], outputs=[historySelectList], show_progress=False, ) diff --git a/modules/models/OpenAIVision.py b/modules/models/OpenAIVision.py index 3bdb7b64..5e0bc827 100644 --- a/modules/models/OpenAIVision.py +++ b/modules/models/OpenAIVision.py @@ -290,7 +290,7 @@ def _single_query_at_once(self, history, temperature=1.0): return response - def auto_name_chat_history(self, name_chat_method, user_question, chatbot, single_turn_checkbox): + def auto_name_chat_history(self, name_chat_method, user_question, single_turn_checkbox): if len(self.history) == 2 and not single_turn_checkbox and not hide_history_when_not_logged_in: user_question = self.history[0]["content"] if name_chat_method == i18n("模型自动总结(消耗tokens)"): @@ -307,10 +307,10 @@ def auto_name_chat_history(self, name_chat_method, user_question, chatbot, singl except Exception as e: logging.info(f"自动命名失败。{e}") filename = replace_special_symbols(user_question)[:16] + ".json" - return self.rename_chat_history(filename, chatbot) + return self.rename_chat_history(filename) elif name_chat_method == i18n("第一条提问"): filename = replace_special_symbols(user_question)[:16] + ".json" - return self.rename_chat_history(filename, chatbot) + return self.rename_chat_history(filename) else: return gr.update() else: diff --git a/modules/models/base_model.py b/modules/models/base_model.py index 0f869b9b..39f5be0f 100644 --- a/modules/models/base_model.py +++ b/modules/models/base_model.py @@ -758,7 +758,6 @@ def retry( iter = self.predict( inputs, chatbot, - stream=self.stream, use_websearch=use_websearch, files=files, reply_language=reply_language, @@ -944,7 +943,7 @@ def token_message(self, token_lst=None): + f"{token_sum} tokens" ) - def rename_chat_history(self, filename, chatbot): + def rename_chat_history(self, filename): if filename == "": return gr.update() if not filename.endswith(".json"): @@ -965,14 +964,14 @@ def rename_chat_history(self, filename, chatbot): return init_history_list(self.user_name) def auto_name_chat_history( - self, name_chat_method, user_question, chatbot, single_turn_checkbox + self, name_chat_method, user_question, single_turn_checkbox ): if len(self.history) == 2 and not single_turn_checkbox: user_question = self.history[0]["content"] if type(user_question) == list: user_question = user_question[0]["text"] filename = replace_special_symbols(user_question)[:16] + ".json" - return self.rename_chat_history(filename, chatbot) + return self.rename_chat_history(filename) else: return gr.update() @@ -1039,6 +1038,7 @@ def load_chat_history(self, new_history_file_path=None): -len(saved_json["chatbot"]) : ] logging.info(f"Trimmed history: {saved_json['history']}") + # Sanitize chatbot saved_json["chatbot"] = remove_html_tags(saved_json["chatbot"]) logging.debug(f"{self.user_name} 加载对话历史完毕") diff --git a/modules/utils.py b/modules/utils.py index bda2f031..9841bf99 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -249,8 +249,6 @@ def clean_text(text): cleaned = re.sub(r'<[^>]+>', '', text) # Remove any remaining HTML entities cleaned = re.sub(r'&[#\w]+;', '', cleaned) - # Remove extra whitespace and newlines - cleaned = re.sub(r'\s+', ' ', cleaned) return cleaned.strip() return [