Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Refactor get_choice_delta_text for safer dict access

程允权a68c3442bcff
diff --git a/metagpt/provider/base_llm.py b/metagpt/provider/base_llm.py
index a50cdacd9..47c527b97 100644
--- a/metagpt/provider/base_llm.py
+++ b/metagpt/provider/base_llm.py
@@ -91,7 +91,7 @@ class BaseLLM(ABC):
def get_choice_delta_text(self, rsp: dict) -> str:
"""Required to provide the first text of stream choice"""
- return rsp.get("choices")[0]["delta"]["content"]
+ return rsp.get("choices", [{}])[0].get("delta", {}).get("content", "")
def get_choice_function(self, rsp: dict) -> dict:
"""Required to provide the first function of choice