From 711032c480a02e9b41ce0148e7d71e84286831dd Mon Sep 17 00:00:00 2001 From: "magic.chen" Date: Thu, 30 Nov 2023 15:11:00 +0800 Subject: [PATCH] fix(llmproxy): fix openai chatgpt api response error (#871) --- pilot/model/proxy/llms/chatgpt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pilot/model/proxy/llms/chatgpt.py b/pilot/model/proxy/llms/chatgpt.py index d0adaf606..c3605ec36 100644 --- a/pilot/model/proxy/llms/chatgpt.py +++ b/pilot/model/proxy/llms/chatgpt.py @@ -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"]