From d46df34ff5fe72ffb88fdd5599e6b5b17d13ff13 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Thu, 1 Feb 2024 09:53:33 -0800 Subject: [PATCH] fix(utils.py): fix streaming chunks to not return role, unless set --- litellm/llms/ollama.py | 10 +++++----- litellm/utils.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/litellm/llms/ollama.py b/litellm/llms/ollama.py index 0f99622b32..c8847117e3 100644 --- a/litellm/llms/ollama.py +++ b/litellm/llms/ollama.py @@ -145,8 +145,8 @@ def get_ollama_response( ): # completion(top_k=3) > cohere_config(top_k=3) <- allows for dynamic variables to be passed in optional_params[k] = v - optional_params["stream"] = optional_params.get("stream", False) - data = {"model": model, "prompt": prompt, **optional_params} + stream = optional_params.pop("stream", False) + data = {"model": model, "prompt": prompt, "options": optional_params} ## LOGGING logging_obj.pre_call( input=None, @@ -159,7 +159,7 @@ def get_ollama_response( }, ) if acompletion is True: - if optional_params.get("stream", False) == True: + if stream == True: response = ollama_async_streaming( url=url, data=data, @@ -176,7 +176,7 @@ def get_ollama_response( logging_obj=logging_obj, ) return response - elif optional_params.get("stream", False) == True: + elif stream == True: return ollama_completion_stream(url=url, data=data, logging_obj=logging_obj) response = requests.post(url=f"{url}", json=data, timeout=litellm.request_timeout) @@ -254,7 +254,7 @@ async def ollama_async_streaming(url, data, model_response, encoding, logging_ob ) as response: if response.status_code != 200: raise OllamaError( - status_code=response.status_code, message=response.text + status_code=response.status_code, message=await response.aread() ) streamwrapper = litellm.CustomStreamWrapper( diff --git a/litellm/utils.py b/litellm/utils.py index a954353c60..d3107d758a 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -233,7 +233,8 @@ class Delta(OpenAIObject): def __init__(self, content=None, role=None, **params): super(Delta, self).__init__(**params) self.content = content - self.role = role + if role is not None: + self.role = role def __contains__(self, key): # Define custom behavior for the 'in' operator