From c5319755699e836900f1e8dd5d62119f117787a9 Mon Sep 17 00:00:00 2001 From: nex Date: Mon, 13 Nov 2023 19:49:57 +0000 Subject: [PATCH] Fix ollama being unable to decode partial chunk --- cogs/other.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/other.py b/cogs/other.py index 547de72..49ba29c 100644 --- a/cogs/other.py +++ b/cogs/other.py @@ -93,10 +93,10 @@ async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerato dict[str, str | int | bool], None ]: print("Starting to iterate over ollama response %r..." % response, file=sys.stderr) - async for chunk in response.aiter_bytes(): - # Each chunk is a JSON string + async for chunk in response.aiter_lines(): + # Each line is a JSON string try: - loaded = json.loads(chunk.strip().decode("utf-8", "replace")) + loaded = json.loads(chunk) print("Loaded chunk: %r" % loaded) yield loaded except json.JSONDecodeError as e: