提交 0f3fc523 作者: imClumsyPanda

update webui.py and api.py

上级 483b7dd2
...@@ -266,7 +266,7 @@ async def bing_search_chat( ...@@ -266,7 +266,7 @@ async def bing_search_chat(
): ):
pass pass
source_documents = [ source_documents = [
f"""出处 [{inum + 1}] {doc.metadata['source']}:\n\n{doc.page_content}\n\n""" f"""出处 [{inum + 1}] <a href="{doc.metadata["source"]}" target="_blank">{doc.metadata["source"]}</a> \n\n{doc.page_content}\n\n"""
for inum, doc in enumerate(resp["source_documents"]) for inum, doc in enumerate(resp["source_documents"])
] ]
......
...@@ -41,7 +41,19 @@ flag_csv_logger = gr.CSVLogger() ...@@ -41,7 +41,19 @@ flag_csv_logger = gr.CSVLogger()
def get_answer(query, vs_path, history, mode, score_threshold=VECTOR_SEARCH_SCORE_THRESHOLD, 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, vector_search_top_k=VECTOR_SEARCH_TOP_K, chunk_conent: bool = True,
chunk_size=CHUNK_SIZE, streaming: bool = STREAMING): 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"""<details> <summary>出处 [{i + 1}] <a href="{doc.metadata["source"]}" target="_blank">{doc.metadata["source"]}</a> </summary>\n"""
f"""{doc.page_content}\n"""
f"""</details>"""
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( for resp, history in local_doc_qa.get_knowledge_based_answer(
query=query, vs_path=vs_path, chat_history=history, streaming=streaming): query=query, vs_path=vs_path, chat_history=history, streaming=streaming):
source = "\n\n" source = "\n\n"
...@@ -264,7 +276,7 @@ with gr.Blocks(css=block_css, theme=gr.themes.Default(**default_theme_args)) as ...@@ -264,7 +276,7 @@ with gr.Blocks(css=block_css, theme=gr.themes.Default(**default_theme_args)) as
query = gr.Textbox(show_label=False, query = gr.Textbox(show_label=False,
placeholder="请输入提问内容,按回车进行提交").style(container=False) placeholder="请输入提问内容,按回车进行提交").style(container=False)
with gr.Column(scale=5): with gr.Column(scale=5):
mode = gr.Radio(["LLM 对话", "知识库问答"], mode = gr.Radio(["LLM 对话", "知识库问答", "Bing搜索问答"],
label="请选择使用模式", label="请选择使用模式",
value="知识库问答", ) value="知识库问答", )
knowledge_set = gr.Accordion("知识库设定", visible=False) knowledge_set = gr.Accordion("知识库设定", visible=False)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论