fix webui: create and rename chat session

This commit is contained in:
liunux4odoo 2023-08-12 22:30:21 +08:00
parent 9514ec1944
commit 1535059d2c
2 changed files with 11 additions and 4 deletions

View File

@ -56,11 +56,14 @@ if __name__ == "__main__":
def on_page_change(key):
cur_chat_name = st.session_state["cur_chat_name"]
if (st.session_state[key] == "新建对话"
and not st.session_state.chat_list[cur_chat_name].get("need_rename")):
and cur_chat_name != "新建对话"
and not st.session_state.get("prompt")):
new_chat_name = f"对话{len(st.session_state.chat_list) + 1}"
st.session_state.chat_list[new_chat_name] = {"need_rename": True}
st.session_state["cur_chat_name"] = new_chat_name
st.session_state[key] = new_chat_name
elif st.session_state[key] not in ["新建对话", "知识库管理"]:
st.session_state["cur_chat_name"] = st.session_state[key]
with st.sidebar:
selected_page = option_menu(

View File

@ -81,12 +81,16 @@ def dialogue_page(api: ApiRequest):
# Display chat messages from history on app rerun
chat_box.output_messages()
if st.session_state.chat_list[st.session_state.cur_chat_name]["need_rename"]:
if (st.session_state.cur_chat_name == "新建对话"
or st.session_state.chat_list.get(st.session_state.cur_chat_name, {}).get("need_rename")):
chat_input_placeholder = "请输入对话名称"
else:
chat_input_placeholder = "请输入对话内容换行请使用Ctrl+Enter "
if prompt := st.chat_input(chat_input_placeholder):
if st.session_state.chat_list[st.session_state.cur_chat_name]["need_rename"]:
if prompt := st.chat_input(chat_input_placeholder, key="prompt"):
if (st.session_state.cur_chat_name == "新建对话"
or st.session_state.chat_list.get(st.session_state.cur_chat_name, {}).get("need_rename")):
if prompt in st.session_state.chat_list.keys():
st.toast("已有同名对话,请重新命名")
else: