fix(llmproxy): fix openai chatgpt api response error (#871)

This commit is contained in:
magic.chen 2023-11-30 15:11:00 +08:00 committed by GitHub
parent 1a8616dab8
commit 711032c480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -175,7 +175,7 @@ def chatgpt_generate_stream(
# 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"):
if len(r.choices) == 0:
continue
if r.choices[0].delta.content is not None:
content = r.choices[0].delta.content
@ -191,7 +191,7 @@ def chatgpt_generate_stream(
text = ""
for r in res:
if not r.get("choices"):
if len(r.choices) == 0:
continue
if r["choices"][0]["delta"].get("content") is not None:
content = r["choices"][0]["delta"]["content"]