36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
|
|
import streamlit as st
|
|||
|
|
from webui_pages.utils import *
|
|||
|
|
from streamlit_chatbox import *
|
|||
|
|
|
|||
|
|
chat_box = ChatBox()
|
|||
|
|
|
|||
|
|
def dialogue_page():
|
|||
|
|
with st.sidebar:
|
|||
|
|
dialogue_mode = st.radio("请选择对话模式",
|
|||
|
|
["LLM 对话",
|
|||
|
|
"知识库问答",
|
|||
|
|
"Bing 搜索问答"])
|
|||
|
|
history_len = st.slider("历史对话轮数:", 1, 10, 1)
|
|||
|
|
if dialogue_mode == "知识库问答":
|
|||
|
|
selected_kb = st.selectbox("请选择知识库:", get_kb_list())
|
|||
|
|
with st.expander(f"{selected_kb} 中已存储文件"):
|
|||
|
|
st.write(get_kb_files(selected_kb))
|
|||
|
|
|
|||
|
|
# Display chat messages from history on app rerun
|
|||
|
|
chat_box.output_messages()
|
|||
|
|
|
|||
|
|
if prompt := st.chat_input("请输入对话内容,换行请使用Ctrl+Enter"):
|
|||
|
|
chat_box.user_say(prompt)
|
|||
|
|
chat_box.ai_say("正在思考...")
|
|||
|
|
# with api.chat_fastchat([{"role": "user", "content": "prompt"}], stream=streaming) as r: # todo: support history len
|
|||
|
|
text = ""
|
|||
|
|
r = api.chat_chat(prompt, no_remote_api=True)
|
|||
|
|
for t in r:
|
|||
|
|
text += t
|
|||
|
|
chat_box.update_msg(text)
|
|||
|
|
chat_box.update_msg(text, streaming=False)
|
|||
|
|
# with api.chat_chat(prompt) as r:
|
|||
|
|
# for t in r.iter_text(None):
|
|||
|
|
# text += t
|
|||
|
|
# chat_box.update_msg(text)
|
|||
|
|
# chat_box.update_msg(text, streaming=False)
|