This commit is contained in:
Nexus 2023-11-10 23:45:52 +00:00
parent 9784b65b1c
commit 7fde67efe0
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -90,11 +90,12 @@ except Exception as _pyttsx3_err:
async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerator[ async def ollama_stream_reader(response: httpx.Response) -> typing.AsyncGenerator[
dict[str, str | int | bool], None dict[str, str | int | bool], None
]: ]:
async for chunk in response.aiter_bytes(8192): 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 # Each chunk is a JSON string
try: try:
loaded = json.loads(chunk.strip().decode("utf-8", "replace")) loaded = json.loads(chunk.strip().decode("utf-8", "replace"))
print("Loaded chunk: %r", loaded) print("Loaded chunk: %r" % loaded)
yield loaded yield loaded
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
print("Failed to decode chunk %r: %r" % (chunk, e), file=sys.stderr) print("Failed to decode chunk %r: %r" % (chunk, e), file=sys.stderr)