Update api.py (#628)

修复websocket的伪流式输出
This commit is contained in:
zzxs 2023-07-02 13:42:53 +08:00 committed by GitHub
parent b922970ac2
commit 6ab496ea4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

3
api.py
View File

@ -4,7 +4,7 @@ import os
import shutil import shutil
from typing import List, Optional from typing import List, Optional
import urllib import urllib
import asyncio
import nltk import nltk
import pydantic import pydantic
import uvicorn 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( for resp, history in local_doc_qa.get_knowledge_based_answer(
query=question, vs_path=vs_path, chat_history=history, streaming=True query=question, vs_path=vs_path, chat_history=history, streaming=True
): ):
await asyncio.sleep(0)
await websocket.send_text(resp["result"][last_print_len:]) await websocket.send_text(resp["result"][last_print_len:])
last_print_len = len(resp["result"]) last_print_len = len(resp["result"])