Skip to content

Commit

Permalink
close #1172: 给webui_page/utils添加一些log信息,方便定位错误
Browse files Browse the repository at this point in the history
  • Loading branch information
liunux4odoo committed Aug 26, 2023
1 parent 9ca53fa commit 8490aae
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions webui_pages/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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):
Expand Down Expand Up @@ -224,9 +225,17 @@ def _httpx_stream2generator(
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’ 已正常启动。"
Expand Down Expand Up @@ -274,6 +283,9 @@ def chat_fastchat(
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,
Expand All @@ -300,6 +312,9 @@ def chat_chat(
"stream": stream,
}

print(f"received input message:")
pprint(data)

if no_remote_api:
from server.chat.chat import chat
response = chat(**data)
Expand Down Expand Up @@ -334,6 +349,9 @@ def knowledge_base_chat(
"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)
Expand Down Expand Up @@ -367,6 +385,9 @@ def search_engine_chat(
"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)
Expand Down

0 comments on commit 8490aae

Please sign in to comment.