Fix ollama being unable to decode partial chunk

This commit is contained in:
Nexus 2023-11-13 19:49:57 +00:00
parent ed277d9f1f
commit c531975569
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -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: