From 19c0db88218933333689654cfb8452d692aed868 Mon Sep 17 00:00:00 2001 From: yzlin Date: Tue, 12 Mar 2024 18:05:50 +0800 Subject: [PATCH] fix empty choices error when using azure --- metagpt/provider/openai_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 2126505c7..8f3b71c42 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -87,7 +87,9 @@ class OpenAILLM(BaseLLM): collected_messages = [] async for chunk in response: chunk_message = chunk.choices[0].delta.content or "" if chunk.choices else "" # extract the message - finish_reason = chunk.choices[0].finish_reason if hasattr(chunk.choices[0], "finish_reason") else None + finish_reason = ( + chunk.choices[0].finish_reason if chunk.choices and hasattr(chunk.choices[0], "finish_reason") else None + ) log_llm_stream(chunk_message) collected_messages.append(chunk_message) if finish_reason: