修复重建知识库界面无反应的问题,添加一些log信息 (#1258)

* close #1172: 给webui_page/utils添加一些log信息,方便定位错误

* 修复:重建知识库时页面未实时显示进度

---------

Co-authored-by: liunux4odoo <liunu@qq.com>
This commit is contained in:
liunux4odoo 2023-08-26 18:26:38 +08:00 committed by GitHub
parent 9ca53fa3ad
commit 96f69edf7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 6 deletions

View File

@ -183,7 +183,7 @@ async def recreate_vector_store(
set allow_empty_kb to True make it applied on empty knowledge base which it not in the info.db or having no documents.
'''
async def output():
def output():
kb = KBServiceFactory.get_service(knowledge_base_name, vs_type, embed_model)
if not kb.exists() and not allow_empty_kb:
yield {"code": 404, "msg": f"未找到知识库 {knowledge_base_name}"}

View File

@ -244,7 +244,6 @@ def knowledge_base_page(api: ApiRequest):
cols = st.columns(3)
# todo: freezed
if cols[0].button(
"依据源文件重建向量库",
# help="无需上传文件通过其它方式将文档拷贝到对应知识库content目录下点击本按钮即可重建知识库。",
@ -258,7 +257,7 @@ def knowledge_base_page(api: ApiRequest):
if msg := check_error_msg(d):
st.toast(msg)
else:
empty.progress(d["finished"] / d["total"], f"正在处理: {d['doc']}")
empty.progress(d["finished"] / d["total"], d["msg"])
st.experimental_rerun()
if cols[2].button(

View File

@ -25,6 +25,7 @@ from server.utils import run_async, iter_over_async
from configs.model_config import NLTK_DATA_PATH
import nltk
nltk.data.path = [NLTK_DATA_PATH] + nltk.data.path
from pprint import pprint
def set_httpx_timeout(timeout=60.0):
@ -224,9 +225,17 @@ class ApiRequest:
try:
with response as r:
for chunk in r.iter_text(None):
if as_json and chunk:
yield json.loads(chunk)
elif chunk.strip():
if not chunk: # fastchat api yield empty bytes on start and end
continue
if as_json:
try:
data = json.loads(chunk)
pprint(data, depth=1)
yield data
except Exception as e:
logger.error(f"接口返回json错误 {chunk}’。错误信息是:{e}")
else:
print(chunk, end="", flush=True)
yield chunk
except httpx.ConnectError as e:
msg = f"无法连接API服务器请确认 api.py 已正常启动。"
@ -274,6 +283,9 @@ class ApiRequest:
return self._fastapi_stream2generator(response)
else:
data = msg.dict(exclude_unset=True, exclude_none=True)
print(f"received input message:")
pprint(data)
response = self.post(
"/chat/fastchat",
json=data,
@ -300,6 +312,9 @@ class ApiRequest:
"stream": stream,
}
print(f"received input message:")
pprint(data)
if no_remote_api:
from server.chat.chat import chat
response = chat(**data)
@ -334,6 +349,9 @@ class ApiRequest:
"local_doc_url": no_remote_api,
}
print(f"received input message:")
pprint(data)
if no_remote_api:
from server.chat.knowledge_base_chat import knowledge_base_chat
response = knowledge_base_chat(**data)
@ -367,6 +385,9 @@ class ApiRequest:
"stream": stream,
}
print(f"received input message:")
pprint(data)
if no_remote_api:
from server.chat.search_engine_chat import search_engine_chat
response = search_engine_chat(**data)