2024-12-20 16:04:03 +08:00
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st
|
|
|
|
|
|
import streamlit_antd_components as sac
|
|
|
|
|
|
|
|
|
|
|
|
from chatchat import __version__
|
|
|
|
|
|
from chatchat.server.utils import api_address
|
|
|
|
|
|
from chatchat.webui_pages.dialogue.dialogue import dialogue_page
|
|
|
|
|
|
from chatchat.webui_pages.kb_chat import kb_chat
|
|
|
|
|
|
from chatchat.webui_pages.knowledge_base.knowledge_base import knowledge_base_page
|
|
|
|
|
|
from chatchat.webui_pages.utils import *
|
|
|
|
|
|
|
|
|
|
|
|
api = ApiRequest(base_url=api_address())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
is_lite = "lite" in sys.argv # TODO: remove lite mode
|
|
|
|
|
|
|
|
|
|
|
|
st.set_page_config(
|
|
|
|
|
|
"Langchain-Chatchat WebUI",
|
|
|
|
|
|
get_img_base64("chatchat_icon_blue_square_v2.png"),
|
|
|
|
|
|
initial_sidebar_state="expanded",
|
|
|
|
|
|
menu_items={
|
|
|
|
|
|
"Get Help": "https://github.com/chatchat-space/Langchain-Chatchat",
|
|
|
|
|
|
"Report a bug": "https://github.com/chatchat-space/Langchain-Chatchat/issues",
|
|
|
|
|
|
"About": f"""欢迎使用 Langchain-Chatchat WebUI {__version__}!""",
|
|
|
|
|
|
},
|
|
|
|
|
|
layout="centered",
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# use the following code to set the app to wide mode and the html markdown to increase the sidebar width
|
|
|
|
|
|
st.markdown(
|
|
|
|
|
|
"""
|
|
|
|
|
|
<style>
|
|
|
|
|
|
[data-testid="stSidebarUserContent"] {
|
|
|
|
|
|
padding-top: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.block-container {
|
|
|
|
|
|
padding-top: 25px;
|
|
|
|
|
|
}
|
|
|
|
|
|
[data-testid="stBottomBlockContainer"] {
|
|
|
|
|
|
padding-bottom: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
""",
|
|
|
|
|
|
unsafe_allow_html=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
with st.sidebar:
|
|
|
|
|
|
st.image(
|
2024-12-29 15:59:16 +08:00
|
|
|
|
get_img_base64("logo-long-chatchat-trans-v2.png"), use_container_width=True
|
2024-12-20 16:04:03 +08:00
|
|
|
|
)
|
|
|
|
|
|
st.caption(
|
|
|
|
|
|
f"""<p align="right">当前版本:{__version__}</p>""",
|
|
|
|
|
|
unsafe_allow_html=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
selected_page = sac.menu(
|
|
|
|
|
|
[
|
|
|
|
|
|
sac.MenuItem("多功能对话", icon="chat"),
|
|
|
|
|
|
sac.MenuItem("RAG 对话", icon="database"),
|
|
|
|
|
|
sac.MenuItem("知识库管理", icon="hdd-stack"),
|
|
|
|
|
|
],
|
|
|
|
|
|
key="selected_page",
|
|
|
|
|
|
open_index=0,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
sac.divider()
|
|
|
|
|
|
|
|
|
|
|
|
if selected_page == "知识库管理":
|
|
|
|
|
|
knowledge_base_page(api=api, is_lite=is_lite)
|
|
|
|
|
|
elif selected_page == "RAG 对话":
|
|
|
|
|
|
kb_chat(api=api)
|
|
|
|
|
|
else:
|
2025-01-05 18:31:03 +08:00
|
|
|
|
#多功能对话
|
2024-12-20 16:04:03 +08:00
|
|
|
|
dialogue_page(api=api, is_lite=is_lite)
|
2025-01-05 18:31:03 +08:00
|
|
|
|
#本来想增加LLM可选模版的对话,后来发现多功能对话已经包含
|
|
|
|
|
|
# else:
|
|
|
|
|
|
# #LLM对话
|
|
|
|
|
|
# llm_dialogue_page(api=api, is_lite=is_lite)
|