zhoutongqing:添加重新构建知识库功能 (#418)

Co-authored-by: imClumsyPanda <littlepanda0716@gmail.com>
This commit is contained in:
zhoutongqing 2023-05-30 20:32:42 +08:00 committed by GitHub
parent f7044f6fe0
commit 875dae64bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -229,6 +229,22 @@ def add_vs_name(vs_name, chatbot):
chatbot = chatbot + [[None, vs_status]]
return gr.update(visible=True, choices=get_vs_list(), value=vs_name), gr.update(
visible=False), gr.update(visible=False), gr.update(visible=True), chatbot
# 自动化加载固定文件间中文件
def init_set_vector_store(content_dir,vs_id,history):
try:
shutil.rmtree(VS_ROOT_PATH)
vs_path = os.path.join(VS_ROOT_PATH, vs_id)
sentence_size = gr.Number(value=SENTENCE_SIZE, precision=0,
label="文本入库分句长度限制",
interactive=True, visible=True)
vs_path, loaded_files = local_doc_qa.init_knowledge_vector_store(content_dir, vs_path, sentence_size)
model_status = """知识库构建成功"""
except Exception as e:
logger.error(e)
model_status = """知识库构建未成功"""
logger.info(model_status)
return history + [[None, model_status]]
def refresh_vs_list():
@ -470,7 +486,9 @@ with gr.Blocks(css=block_css, theme=gr.themes.Default(**default_theme_args)) as
load_model_button.click(reinit_model, show_progress=True,
inputs=[llm_model, embedding_model, llm_history_len, no_remote_model, use_ptuning_v2,
use_lora, top_k, chatbot], outputs=chatbot)
load_knowlege_button = gr.Button("重新构建知识库")
load_knowlege_button.click(init_set_vector_store, show_progress=True,
inputs=[UPLOAD_ROOT_PATH, select_vs,chatbot], outputs=chatbot)
(demo
.queue(concurrency_count=3)
.launch(server_name='0.0.0.0',