From 6ab496ea4ae9ac5c43e14eafcaa42c882eb87db0 Mon Sep 17 00:00:00 2001 From: zzxs <413284286@qq.com> Date: Sun, 2 Jul 2023 13:42:53 +0800 Subject: [PATCH] Update api.py (#628) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复websocket的伪流式输出 --- api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 0413c95..2c7cd50 100644 --- a/api.py +++ b/api.py @@ -4,7 +4,7 @@ import os import shutil from typing import List, Optional import urllib - +import asyncio import nltk import pydantic import uvicorn @@ -382,6 +382,7 @@ async def stream_chat(websocket: WebSocket, knowledge_base_id: str): for resp, history in local_doc_qa.get_knowledge_based_answer( query=question, vs_path=vs_path, chat_history=history, streaming=True ): + await asyncio.sleep(0) await websocket.send_text(resp["result"][last_print_len:]) last_print_len = len(resp["result"])