diff --git a/src/Chat.py b/src/Chat.py index f03a03a..d6f3a13 100644 --- a/src/Chat.py +++ b/src/Chat.py @@ -190,25 +190,6 @@ def init_new_chat(): use_container_width=True, on_click=init_new_chat, ) - # if new_chat: - # # avoid rerun for new random email,no use clear() - # keys_to_delete = [ - # "selected_chat_id", - # "timestamp", - # "first_run", - # "messages", - # "xata_history", - # "uploaded_files", - # "faiss_db", - # ] - # for key in keys_to_delete: - # try: - # del st.session_state[key] - # except: - # pass - - # del new_chat - # st.rerun() with col_delete: @@ -234,23 +215,6 @@ def delete_chat(): use_container_width=True, on_click=delete_chat, ) - # if delete_chat: - # delete_chat_history(st.session_state["selected_chat_id"]) - # # avoid rerun for new random email, no use clear() - # del st.session_state["selected_chat_id"] - # del st.session_state["timestamp"] - # del st.session_state["first_run"] - # del st.session_state["messages"] - # del st.session_state["xata_history"] - # try: - # del st.session_state["uploaded_files"] - # except: - # pass - # try: - # del st.session_state["faiss_db"] - # except: - # pass - # st.rerun() if "first_run" not in st.session_state: timestamp = time.time() diff --git a/src/utils.py b/src/utils.py index 30b77e5..b1976a0 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1360,12 +1360,12 @@ def your_function(): # to show chat history on ui if "messages" not in st.session_state or len(st.session_state["messages"]) == 1: if "subscription" in st.session_state: - welcome_message = ui.chat_ai_welcome.format( + welcome_message_text = ui.chat_ai_welcome.format( username=st.session_state["username"].split("@")[0], subscription=st.session_state["subsription"], ) else: - welcome_message = ui.chat_ai_welcome.format( + welcome_message_text = ui.chat_ai_welcome.format( username="there", subscription="free" ) @@ -1373,7 +1373,7 @@ def your_function(): { "role": "assistant", "avatar": ui.chat_ai_avatar, - "content": welcome_message, + "content": welcome_message_text, } ] @@ -1542,14 +1542,24 @@ def initialize_messages(history): Exceptions: - Exceptions that may propagate from the `convert_history_to_message` function. """ - # 将历史消息转换为消息格式 + # convert history to message messages = [convert_history_to_message(message) for message in history] - # 在最前面加入欢迎消息 + if "subscription" in st.session_state: + welcome_message_text = ui.chat_ai_welcome.format( + username=st.session_state["username"].split("@")[0], + subscription=st.session_state["subsription"], + ) + else: + welcome_message_text = ui.chat_ai_welcome.format( + username="there", subscription="free" + ) + + # add welcome message welcome_message = { "role": "assistant", "avatar": ui.chat_ai_avatar, - "content": ui.chat_ai_welcome, + "content": welcome_message_text, } messages.insert(0, welcome_message)