from fastapi.responses import StreamingResponse
from tqdm import tqdm
from pydantic import BaseModel
classItemDataSingle(BaseModel):
data:strasyncdefresponce_text_streammer(data):
_data = data.data
# 假设你发送过来的
data = json.loads(_data)for dat in tqdm(data):
dat = your_worker_function(dat)# 给每条数据一个分割标识yield json.dumps(dat,ensure_ascii=False)+"@@+"@app.post("/batchtext2furniture")asyncdefbatchtext2furniture(data: ItemDataSingle,):"""
:arg
"""# mongodbreturn StreamingResponse(responce_text_streammer(data))