Merge pull request #801 from pkdog/fix-zhipu

Refactor get_choice_delta_text for safer dict access while using ZHIPU API
This commit is contained in:
geekan 2024-01-31 23:35:03 +08:00 committed by GitHub
commit d35527b0ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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