This commit is contained in:
Nexus 2023-11-10 23:29:23 +00:00
parent a6e92a44af
commit 0f9fc8b7b9
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -92,12 +92,14 @@ async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerato
]: ]:
_buffer = b"" _buffer = b""
async for char in response.aiter_bytes(1): async for char in response.aiter_bytes(1):
while not _buffer.endswith(b"}\n"): while not _buffer.endswith(b"\n"):
_buffer += char _buffer += char
print( print(
"Read {:,} bytes in chunk for a total of {:,} bytes in buffer.".format( "Read {:,} bytes ({!r}) in chunk for a total of {:,} bytes in buffer ({!r}).".format(
len(char), len(char),
len(_buffer) char,
len(_buffer),
_buffer
) )
) )
_buffer = _buffer.rstrip() _buffer = _buffer.rstrip()