From 4028f935a5760fc6bb383f43f2000db642dcfbe8 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 26 Mar 2024 14:39:16 -0700 Subject: [PATCH] fix(utils.py): check if item in list is pydantic object or dict before dereferencing --- litellm/utils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index 00d627c6b6..713861dad0 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -500,7 +500,10 @@ class ModelResponse(OpenAIObject): if choices is not None and isinstance(choices, list): new_choices = [] for choice in choices: - _new_choice = StreamingChoices(**choice) + if isinstance(choice, StreamingChoices): + _new_choice = choice + elif isinstance(choice, dict): + _new_choice = StreamingChoices(**choice) new_choices.append(_new_choice) choices = new_choices else: @@ -513,7 +516,10 @@ class ModelResponse(OpenAIObject): if choices is not None and isinstance(choices, list): new_choices = [] for choice in choices: - _new_choice = Choices(**choice) + if isinstance(choice, Choices): + _new_choice = choice + elif isinstance(choice, dict): + _new_choice = Choices(**choice) new_choices.append(_new_choice) choices = new_choices else: