From c4b1540ce067f93f5546000731e2cf2dae91a143 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Sat, 22 Jun 2024 15:45:52 -0700 Subject: [PATCH] fix(utils.py): support streamingchoices in 'get_response_string --- litellm/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index b734ae465..2b9660bfc 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3896,12 +3896,16 @@ def get_formatted_prompt( def get_response_string(response_obj: ModelResponse) -> str: - _choices: List[Choices] = response_obj.choices # type: ignore + _choices: List[Union[Choices, StreamingChoices]] = response_obj.choices response_str = "" for choice in _choices: - if choice.message.content is not None: - response_str += choice.message.content + if isinstance(choice, Choices): + if choice.message.content is not None: + response_str += choice.message.content + elif isinstance(choice, StreamingChoices): + if choice.delta.content is not None: + response_str += choice.delta.content return response_str