From a68c3442bcff09864409ed47a02bbcc476657d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=85=81=E6=9D=83?= Date: Sun, 28 Jan 2024 10:39:00 +0800 Subject: [PATCH] Refactor get_choice_delta_text for safer dict access --- metagpt/provider/base_llm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ def get_choice_text(self, rsp: dict) -> str: 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