From 33c36659229c1e4294d23d8bd48851e99366cba6 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Sat, 18 Nov 2023 17:31:58 -0800 Subject: [PATCH] (fix) streaming ensure response obj is initialized --- litellm/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index f7a81a86eb2..40d8a72aecd 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4714,6 +4714,7 @@ class CustomStreamWrapper: def chunk_creator(self, chunk): model_response = ModelResponse(stream=True, model=self.model) model_response.choices[0].finish_reason = None + response_obj = None try: # return this for all models completion_obj = {"content": ""} @@ -4865,7 +4866,7 @@ class CustomStreamWrapper: return model_response else: return - elif response_obj.get("original_chunk", None) is not None: # function / tool calling branch + elif response_obj is not None and response_obj.get("original_chunk", None) is not None: # function / tool calling branch - only set for openai/azure compatible endpoints original_chunk = response_obj.get("original_chunk", None) model_response.id = original_chunk.id delta = dict(original_chunk.choices[0].delta)