mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-01 00:03:29 +00:00
bugfix(Azure): fix index out of range error due to Azure Openai reponses an empty chunk at first (#820)
Co-authored-by: 一帆 <zhang.f@digitalcnzz.com>
This commit is contained in:
parent
d9cc1020c1
commit
0b02451fb3
@ -172,6 +172,11 @@ def chatgpt_generate_stream(
|
||||
res = client.chat.completions.create(messages=history, **payloads)
|
||||
text = ""
|
||||
for r in res:
|
||||
# logger.info(str(r))
|
||||
# Azure Openai reponse may have empty choices body in the first chunk
|
||||
# to avoid index out of range error
|
||||
if not r.get("choices"):
|
||||
continue
|
||||
if r.choices[0].delta.content is not None:
|
||||
content = r.choices[0].delta.content
|
||||
text += content
|
||||
@ -186,6 +191,8 @@ def chatgpt_generate_stream(
|
||||
|
||||
text = ""
|
||||
for r in res:
|
||||
if not r.get("choices"):
|
||||
continue
|
||||
if r["choices"][0]["delta"].get("content") is not None:
|
||||
content = r["choices"][0]["delta"]["content"]
|
||||
text += content
|
||||
@ -220,6 +227,8 @@ async def async_chatgpt_generate_stream(
|
||||
res = await client.chat.completions.create(messages=history, **payloads)
|
||||
text = ""
|
||||
for r in res:
|
||||
if not r.get("choices"):
|
||||
continue
|
||||
if r.choices[0].delta.content is not None:
|
||||
content = r.choices[0].delta.content
|
||||
text += content
|
||||
@ -233,6 +242,8 @@ async def async_chatgpt_generate_stream(
|
||||
|
||||
text = ""
|
||||
async for r in res:
|
||||
if not r.get("choices"):
|
||||
continue
|
||||
if r["choices"][0]["delta"].get("content") is not None:
|
||||
content = r["choices"][0]["delta"]["content"]
|
||||
text += content
|
||||
|
Loading…
Reference in New Issue
Block a user