fix(utils.py): check if item in list is pydantic object or dict before dereferencing

This commit is contained in:
Krrish Dholakia 2024-03-26 14:39:16 -07:00
parent a0f55b92e6
commit 4028f935a5

View file

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