From e214e6ab47c6ac9f3349ce07f6ba41a367cc5b69 Mon Sep 17 00:00:00 2001 From: Joel Eriksson Date: Sun, 17 Dec 2023 20:23:26 +0200 Subject: [PATCH] Fix bug when iterating over lines in ollama response async for line in resp.content.iter_any() will return incomplete lines when the lines are long, and that results in an exception being thrown by json.loads() when it tries to parse the incomplete JSON The default behavior of the stream reader for aiohttp response objects is to iterate over lines, so just removing .iter_any() fixes the bug --- litellm/llms/ollama.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/llms/ollama.py b/litellm/llms/ollama.py index f2a9b0df4d..e2be1c2d5d 100644 --- a/litellm/llms/ollama.py +++ b/litellm/llms/ollama.py @@ -195,7 +195,7 @@ async def ollama_acompletion(url, data, model_response, encoding, logging_obj): raise OllamaError(status_code=resp.status, message=text) completion_string = "" - async for line in resp.content.iter_any(): + async for line in resp.content: if line: try: json_chunk = line.decode("utf-8")