2023-09-28 10:58:58 +08:00
|
|
|
|
# 运行方式:
|
|
|
|
|
# 1. 安装必要的包:pip install streamlit-option-menu streamlit-chatbox>=1.1.6
|
|
|
|
|
# 2. 运行本机fastchat服务:python server\llm_api.py 或者 运行对应的sh文件
|
|
|
|
|
# 3. 运行API服务器:python server/api.py。如果使用api = ApiRequest(no_remote_api=True),该步可以跳过。
|
|
|
|
|
# 4. 运行WEB UI:streamlit run webui.py --server.port 7860
|
2024-04-23 16:44:13 +08:00
|
|
|
|
from loguru import logger
|
2023-11-07 19:44:47 +08:00
|
|
|
|
import os
|
|
|
|
|
import sys
|
2023-09-28 10:58:58 +08:00
|
|
|
|
import streamlit as st
|
|
|
|
|
from streamlit_option_menu import option_menu
|
|
|
|
|
|
2023-11-07 19:44:47 +08:00
|
|
|
|
import multiprocessing
|
|
|
|
|
|
2023-09-28 10:58:58 +08:00
|
|
|
|
src_dir = os.path.join(
|
|
|
|
|
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
)
|
|
|
|
|
sys.path.append(src_dir)
|
|
|
|
|
|
2024-01-26 14:03:25 +08:00
|
|
|
|
from webui import *
|
|
|
|
|
from configs.model_config import VERSION, LLM_MODEL
|
2023-11-07 19:44:47 +08:00
|
|
|
|
from configs.server_config import NO_REMOTE_API
|
2024-01-26 14:03:25 +08:00
|
|
|
|
from configs.model_config import CB_ROOT_PATH
|
2023-09-28 10:58:58 +08:00
|
|
|
|
|
2024-01-26 14:03:25 +08:00
|
|
|
|
from configs.model_config import embedding_model_dict, kbs_config, EMBEDDING_MODEL, DEFAULT_VS_TYPE, WEB_CRAWL_PATH
|
2023-09-28 10:58:58 +08:00
|
|
|
|
|
|
|
|
|
|
2024-01-26 14:03:25 +08:00
|
|
|
|
api = ApiRequest(base_url="http://127.0.0.1:7861", no_remote_api=NO_REMOTE_API, cb_root_path=CB_ROOT_PATH)
|
2023-09-28 10:58:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
st.set_page_config(
|
2023-12-26 11:41:53 +08:00
|
|
|
|
"CodeFuse-ChatBot WebUI",
|
2023-09-28 10:58:58 +08:00
|
|
|
|
os.path.join("../sources/imgs", "devops-chatbot.png"),
|
|
|
|
|
initial_sidebar_state="expanded",
|
|
|
|
|
menu_items={
|
2023-12-26 11:41:53 +08:00
|
|
|
|
'Get Help': 'https://github.com/codefuse-ai/codefuse-chatbot',
|
|
|
|
|
'Report a bug': "https://github.com/codefuse-ai/codefuse-chatbot/issues",
|
|
|
|
|
'About': f"""欢迎使用 CodeFuse-ChatBot WebUI {VERSION}!"""
|
2023-09-28 10:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if not chat_box.chat_inited:
|
|
|
|
|
st.toast(
|
2023-12-26 11:41:53 +08:00
|
|
|
|
f"欢迎使用 [`CodeFuse-ChatBot`](https://github.com/codefuse-ai/codefuse-chatbot) ! \n\n"
|
2023-09-28 10:58:58 +08:00
|
|
|
|
f"当前使用模型`{LLM_MODEL}`, 您可以开始提问了."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
pages = {
|
|
|
|
|
"对话": {
|
|
|
|
|
"icon": "chat",
|
|
|
|
|
"func": dialogue_page,
|
|
|
|
|
},
|
|
|
|
|
"知识库管理": {
|
|
|
|
|
"icon": "hdd-stack",
|
|
|
|
|
"func": knowledge_page,
|
|
|
|
|
},
|
2023-11-07 19:44:47 +08:00
|
|
|
|
"代码知识库管理": {
|
|
|
|
|
"icon": "hdd-stack",
|
|
|
|
|
"func": code_page,
|
|
|
|
|
},
|
2023-09-28 10:58:58 +08:00
|
|
|
|
# "Prompt管理": {
|
|
|
|
|
# "icon": "hdd-stack",
|
|
|
|
|
# "func": prompt_page,
|
|
|
|
|
# },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with st.sidebar:
|
|
|
|
|
st.image(
|
|
|
|
|
os.path.join(
|
|
|
|
|
"../sources/imgs",
|
|
|
|
|
"devops-chatbot.png"
|
|
|
|
|
),
|
|
|
|
|
use_column_width=True
|
|
|
|
|
)
|
|
|
|
|
st.caption(
|
2023-12-26 11:41:53 +08:00
|
|
|
|
f"""<p align="right"> CodeFuse-ChatBot 当前版本:{VERSION}</p>""",
|
2023-09-28 10:58:58 +08:00
|
|
|
|
unsafe_allow_html=True,
|
|
|
|
|
)
|
|
|
|
|
options = list(pages)
|
|
|
|
|
icons = [x["icon"] for x in pages.values()]
|
|
|
|
|
|
|
|
|
|
default_index = 0
|
|
|
|
|
selected_page = option_menu(
|
|
|
|
|
"",
|
|
|
|
|
options=options,
|
|
|
|
|
icons=icons,
|
|
|
|
|
# menu_icon="chat-quote",
|
|
|
|
|
default_index=default_index,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if selected_page in pages:
|
|
|
|
|
pages[selected_page]["func"](api)
|
2024-01-26 14:03:25 +08:00
|
|
|
|
# pages["对话"]["func"](api, )
|
|
|
|
|
# pages["知识库管理"]["func"](api, embedding_model_dict, kbs_config, EMBEDDING_MODEL, DEFAULT_VS_TYPE, WEB_CRAWL_PATH)
|
|
|
|
|
# pages["代码知识库管理"]["func"](api, )
|