From 0f3fc5234d86ed26c13ee0c4f95cef5c3498a563 Mon Sep 17 00:00:00 2001 From: imClumsyPanda Date: Sun, 21 May 2023 23:04:46 +0800 Subject: [PATCH] update webui.py and api.py --- api.py | 2 +- webui.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api.py b/api.py index 6f8597a..c0cd1cc 100644 --- a/api.py +++ b/api.py @@ -266,7 +266,7 @@ async def bing_search_chat( ): pass source_documents = [ - f"""出处 [{inum + 1}] {doc.metadata['source']}:\n\n{doc.page_content}\n\n""" + f"""出处 [{inum + 1}] {doc.metadata["source"]} \n\n{doc.page_content}\n\n""" for inum, doc in enumerate(resp["source_documents"]) ] diff --git a/webui.py b/webui.py index 5eb2a1a..d535c9d 100644 --- a/webui.py +++ b/webui.py @@ -41,7 +41,19 @@ flag_csv_logger = gr.CSVLogger() def get_answer(query, vs_path, history, mode, score_threshold=VECTOR_SEARCH_SCORE_THRESHOLD, vector_search_top_k=VECTOR_SEARCH_TOP_K, chunk_conent: bool = True, chunk_size=CHUNK_SIZE, streaming: bool = STREAMING): - if mode == "知识库问答" and vs_path is not None and os.path.exists(vs_path): + if mode == "Bing搜索问答": + for resp, history in local_doc_qa.get_search_result_based_answer( + query=query, chat_history=history, streaming=streaming): + source = "\n\n" + source += "".join( + [f"""
出处 [{i + 1}] {doc.metadata["source"]} \n""" + f"""{doc.page_content}\n""" + f"""
""" + for i, doc in + enumerate(resp["source_documents"])]) + history[-1][-1] += source + yield history, "" + elif mode == "知识库问答" and vs_path is not None and os.path.exists(vs_path): for resp, history in local_doc_qa.get_knowledge_based_answer( query=query, vs_path=vs_path, chat_history=history, streaming=streaming): source = "\n\n" @@ -264,7 +276,7 @@ with gr.Blocks(css=block_css, theme=gr.themes.Default(**default_theme_args)) as query = gr.Textbox(show_label=False, placeholder="请输入提问内容,按回车进行提交").style(container=False) with gr.Column(scale=5): - mode = gr.Radio(["LLM 对话", "知识库问答"], + mode = gr.Radio(["LLM 对话", "知识库问答", "Bing搜索问答"], label="请选择使用模式", value="知识库问答", ) knowledge_set = gr.Accordion("知识库设定", visible=False)