Skip to content

Commit

Permalink
fix #1163
Browse files Browse the repository at this point in the history
  • Loading branch information
GaiZhenbiao committed Sep 18, 2024
1 parent 952fc8c commit d4451bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ChuanhuChatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
6 changes: 3 additions & 3 deletions modules/models/OpenAIVision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"):
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions modules/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,6 @@ def retry(
iter = self.predict(
inputs,
chatbot,
stream=self.stream,
use_websearch=use_websearch,
files=files,
reply_language=reply_language,
Expand Down Expand Up @@ -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"):
Expand All @@ -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()

Expand Down Expand Up @@ -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} 加载对话历史完毕")
Expand Down
2 changes: 0 additions & 2 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit d4451bb

Please sign in to comment.