Skip to content

Commit

Permalink
fix welcome message
Browse files Browse the repository at this point in the history
  • Loading branch information
linancn committed Oct 30, 2023
1 parent 284fff9 commit a7bca5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
36 changes: 0 additions & 36 deletions src/Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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()
Expand Down
22 changes: 16 additions & 6 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,20 +1360,20 @@ 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"
)

st.session_state["messages"] = [
{
"role": "assistant",
"avatar": ui.chat_ai_avatar,
"content": welcome_message,
"content": welcome_message_text,
}
]

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a7bca5e

Please sign in to comment.