feat(core): Support multi round conversation operator (#986)

This commit is contained in:
Fangyin Cheng
2023-12-27 23:26:28 +08:00
committed by GitHub
parent 9aec636b02
commit b13d3f6d92
63 changed files with 2011 additions and 314 deletions

View File

@@ -44,11 +44,20 @@ async def _do_chat_completion(
decoded_line = line.split("data: ", 1)[1]
if decoded_line.lower().strip() != "[DONE]".lower():
obj = json.loads(decoded_line)
if obj["choices"][0]["delta"].get("content") is not None:
text = obj["choices"][0]["delta"].get("content")
if "error_code" in obj and obj["error_code"] != 0:
if caller:
await caller(text)
yield text
await caller(obj.get("text"))
yield obj.get("text")
else:
if (
"choices" in obj
and obj["choices"][0]["delta"].get("content")
is not None
):
text = obj["choices"][0]["delta"].get("content")
if caller:
await caller(text)
yield text
await asyncio.sleep(0.02)