From 608fef60a645e31bf82de2498286b3bcc530f4ab Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 1 May 2024 11:08:44 -0700 Subject: [PATCH] fix(utils.py): check if response_object["choices"] is not none and iterable --- litellm/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index a75a31f13..9cbf817b2 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -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),