fix webui: create and rename chat session
This commit is contained in:
parent
9514ec1944
commit
1535059d2c
5
webui.py
5
webui.py
|
|
@ -56,11 +56,14 @@ if __name__ == "__main__":
|
||||||
def on_page_change(key):
|
def on_page_change(key):
|
||||||
cur_chat_name = st.session_state["cur_chat_name"]
|
cur_chat_name = st.session_state["cur_chat_name"]
|
||||||
if (st.session_state[key] == "新建对话"
|
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}"
|
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.chat_list[new_chat_name] = {"need_rename": True}
|
||||||
st.session_state["cur_chat_name"] = new_chat_name
|
st.session_state["cur_chat_name"] = new_chat_name
|
||||||
st.session_state[key] = 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:
|
with st.sidebar:
|
||||||
selected_page = option_menu(
|
selected_page = option_menu(
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,16 @@ def dialogue_page(api: ApiRequest):
|
||||||
# Display chat messages from history on app rerun
|
# Display chat messages from history on app rerun
|
||||||
|
|
||||||
chat_box.output_messages()
|
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 = "请输入对话名称"
|
chat_input_placeholder = "请输入对话名称"
|
||||||
else:
|
else:
|
||||||
chat_input_placeholder = "请输入对话内容,换行请使用Ctrl+Enter "
|
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():
|
if prompt in st.session_state.chat_list.keys():
|
||||||
st.toast("已有同名对话,请重新命名")
|
st.toast("已有同名对话,请重新命名")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue