diff --git a/litellm/__pycache__/utils.cpython-311.pyc b/litellm/__pycache__/utils.cpython-311.pyc index c4098f31b..189cf63d1 100644 Binary files a/litellm/__pycache__/utils.cpython-311.pyc and b/litellm/__pycache__/utils.cpython-311.pyc differ diff --git a/litellm/tests/test_streaming.py b/litellm/tests/test_streaming.py index 7a20c6cb2..0ec8563ab 100644 --- a/litellm/tests/test_streaming.py +++ b/litellm/tests/test_streaming.py @@ -40,15 +40,13 @@ def test_completion_cohere_stream(): # Add any assertions here to check the response for chunk in response: print(f"chunk: {chunk}") - if "content" in chunk["choices"][0]["delta"]: - complete_response += chunk["choices"][0]["delta"]["content"] + complete_response += chunk["choices"][0]["delta"]["content"] if complete_response == "": raise Exception("Empty response received") print(f"completion_response: {complete_response}") except Exception as e: pytest.fail(f"Error occurred: {e}") - - + # test on baseten completion call # try: # response = completion( @@ -290,8 +288,6 @@ async def ai21_async_completion_call(): complete_response += chunk["choices"][0]["delta"]["content"] if complete_response == "": raise Exception("Empty response received") - except KeyError as e: - pass except: print(f"error occurred: {traceback.format_exc()}") pass \ No newline at end of file diff --git a/litellm/utils.py b/litellm/utils.py index 2a3544abb..77cffe3ad 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -103,7 +103,7 @@ class Choices(OpenAIObject): self.message = message class StreamingChoices(OpenAIObject): - def __init__(self, finish_reason=None, index=0, delta: Optional[Union[Dict, Delta]]={}, **params): + def __init__(self, finish_reason=None, index=0, delta=Delta(), **params): super(StreamingChoices, self).__init__(**params) self.finish_reason = finish_reason self.index = index @@ -2492,11 +2492,12 @@ class CustomStreamWrapper: model_response = ModelResponse(stream=True) model_response.choices[0].delta = completion_obj return model_response + except StopIteration: + raise StopIteration except Exception as e: model_response = ModelResponse(stream=True) model_response.choices[0].finish_reason = "stop" return model_response - # raise StopIteration async def __anext__(self): try: