fix(utils.py): check if response_object["choices"] is not none and iterable

This commit is contained in:
Krrish Dholakia 2024-05-01 11:08:44 -07:00
parent e96ccb8edf
commit 608fef60a6

View file

@ -106,7 +106,7 @@ try:
except Exception as e:
verbose_logger.debug(f"Exception import enterprise features {str(e)}")
from typing import cast, List, Dict, Union, Optional, Literal, Any, BinaryIO
from typing import cast, List, Dict, Union, Optional, Literal, Any, BinaryIO, Iterable
from .caching import Cache
from concurrent.futures import ThreadPoolExecutor
@ -7184,6 +7184,10 @@ def convert_to_model_response_object(
return convert_to_streaming_response(response_object=response_object)
choice_list = []
assert response_object["choices"] is not None and isinstance(
response_object["choices"], Iterable
)
for idx, choice in enumerate(response_object["choices"]):
message = Message(
content=choice["message"].get("content", None),