Unverified 提交 1678392c 作者: royd 提交者: GitHub

Update api.py (#357)

更改目前流式对话的传入模式,使其可以支持多轮对话,体现在新增参数:history、knowledge_base_id
上级 0fca4c95
......@@ -265,6 +265,10 @@ async def chat(
async def stream_chat(websocket: WebSocket, knowledge_base_id: str):
await websocket.accept()
turn = 1
while True:
input_json = await websocket.receive_json()
question, history, knowledge_base_id = input_json[""], input_json["history"], input_json["knowledge_base_id"]
vs_path = os.path.join(VS_ROOT_PATH, knowledge_base_id)
if not os.path.exists(vs_path):
......@@ -272,10 +276,6 @@ async def stream_chat(websocket: WebSocket, knowledge_base_id: str):
await websocket.close()
return
history = []
turn = 1
while True:
question = await websocket.receive_text()
await websocket.send_json({"question": question, "turn": turn, "flag": "start"})
last_print_len = 0
......@@ -304,7 +304,6 @@ async def stream_chat(websocket: WebSocket, knowledge_base_id: str):
)
turn += 1
async def document():
return RedirectResponse(url="/docs")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论