Refactor get_choice_delta_text for safer dict access

This commit is contained in:
程允权 2024-01-28 10:39:00 +08:00
parent ee0801a116
commit a68c3442bc

View file

@ -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